editor: fix selection/focus is lost when editor state is updated

This commit is contained in:
Abdullah Atta
2024-03-09 23:11:37 +05:00
parent 0247903772
commit 1cebcb7876

View File

@@ -60,7 +60,10 @@ export const useEditor = (
editor.schema,
options.parseOptions
);
const selection = resolveFocusPosition(doc, options.autofocus);
const selection =
editor.state.selection ||
resolveFocusPosition(doc, options.autofocus);
const oldIsFocused = editor.isFocused;
editor.view.updateState(
EditorState.create({
doc,
@@ -68,6 +71,7 @@ export const useEditor = (
selection: selection || undefined
})
);
if (oldIsFocused && !editor.isFocused) editor.commands.focus();
}
editor.options = { ...editor.options, ...options };