How to blur
#1515
-
I get
when I delete all values using the
API, seems I need to clear the selection. But I didn't find a good way to do this in plate, how to blur (reset selection)? |
Beta Was this translation helpful? Give feedback.
Answered by
linonetwo
May 5, 2022
Replies: 1 comment
-
This is not working:
I also tried Note that to avoid tiddly-gittly/slate-write#3 bug I'm turning This works: const { resetEditor, value: updateEditorValue } = getPlateActions(editorID);
// update current value from props
useEffect(() => {
// there will be cases that triple return replaced with double return (trim), cause here rerender, but I think it is ok, not so frequent
if (currentTextRef.current !== props.tiddlerText) {
const newValue = deserialize(props.tiddlerText);
currentAstRef.current = newValue;
// reset selection, so if you delete wikitext, selection won't goto some empty space and cause error
resetEditor();
updateEditorValue(newValue);
}
}, [props.tiddlerText, currentTextRef, updateEditorValue, resetEditor]);
useEffect(() => {
// reset selection, so if you delete wikitext, selection won't goto some empty space and cause error
resetEditor();
}, []);
const onBlur = useCallback(() => {
// reset selection, so if you delete wikitext, selection won't goto some empty space and cause error
resetEditor();
}, []);
return (
<Plate id={editorID} initialValue={currentAstRef.current} plugins={plugins} onChange={onChange} editableProps={{ ...CONFIG.editableProps, onBlur }}>
<BallonToolbar />
<SnippetCombobox id={editorID} trigger="/" />
</Plate>
); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
linonetwo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is not working:
I also tried
Transforms.select(editorRef, SlateEditor.start(editorRef, []))
but still not working.Note that to avoid tiddly-gittly/slate-write#3 bug I'm turning
autoFocus: true,
This works: