1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-20 22:21:20 +02:00

fix: update mentions example to slate 0.43 (#2363)

It also works in Safari now :)
This commit is contained in:
Eric Edem
2018-11-01 12:14:44 -07:00
committed by Ian Storm Taylor
parent d5bb44383d
commit 924f84d597

View File

@@ -168,14 +168,14 @@ class MentionsExample extends React.Component {
insertMention = user => { insertMention = user => {
const value = this.state.value const value = this.state.value
const inputValue = getInput(value) const inputValue = getInput(value)
const editor = this.editorRef.current
// Delete the captured value, including the `@` symbol // Delete the captured value, including the `@` symbol
this.editorRef.current.change(change => { editor.deleteBackward(inputValue.length + 1)
change = change.deleteBackward(inputValue.length + 1)
const selectedRange = change.value.selection const selectedRange = editor.value.selection
change editor
.insertText(' ') .insertText(' ')
.insertInlineAtRange(selectedRange, { .insertInlineAtRange(selectedRange, {
data: { data: {
@@ -195,11 +195,6 @@ class MentionsExample extends React.Component {
type: USER_MENTION_NODE_TYPE, type: USER_MENTION_NODE_TYPE,
}) })
.focus() .focus()
this.setState({
value: change.value,
})
})
} }
/** /**
@@ -240,7 +235,11 @@ class MentionsExample extends React.Component {
}) })
} }
return change.withoutSaving(() => change.setDecorations(decorations)) this.setState({ value: change.value }, () => {
// We need to set decorations after the value flushes into the editor.
this.editorRef.current.setDecorations(decorations)
})
return
} }
this.setState({ value: change.value }) this.setState({ value: change.value })