Created
December 31, 2019 18:49
-
-
Save amiri/18b19e32e6812f46870829c78a3df885 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const findLastWord = (editor) => { | |
console.log(editor.selection); | |
Transforms.move(editor, { unit: 'word', reverse: true }) | |
console.log(editor.selection); | |
const selected = Editor.string(editor, editor.selection); | |
console.log(selected); | |
Transforms.move(editor, {unit: 'word'}); | |
editor.insertText(' '); | |
}; | |
// ... | |
return ( | |
<Slate | |
editor={editor} | |
value={value} | |
onChange={change => { | |
onChange(change); | |
setValue(change); | |
}} | |
onBlur={onBlur} | |
> | |
<Toolbar /> | |
<Editable | |
renderElement={renderElement} | |
renderLeaf={renderLeaf} | |
onKeyDown={e => { | |
e.preventDefault(); | |
const lastWord = findLastWord(editor); | |
}} | |
/> | |
</Slate> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment