Skip to content

Instantly share code, notes, and snippets.

@amiri
Created December 31, 2019 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amiri/18b19e32e6812f46870829c78a3df885 to your computer and use it in GitHub Desktop.
Save amiri/18b19e32e6812f46870829c78a3df885 to your computer and use it in GitHub Desktop.
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