From bc3662afc79e8a09b2fcca11b6924ceb777f35f1 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 23 Sep 2023 16:20:09 -0500 Subject: [PATCH] lexical: fix ctrl+Enter --- .../compose/editor/plugins/state-plugin.tsx | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/features/compose/editor/plugins/state-plugin.tsx b/src/features/compose/editor/plugins/state-plugin.tsx index e273f5db1..28dc5431b 100644 --- a/src/features/compose/editor/plugins/state-plugin.tsx +++ b/src/features/compose/editor/plugins/state-plugin.tsx @@ -15,13 +15,18 @@ const StatePlugin = ({ composeId, handleSubmit }: IStatePlugin) => { const [editor] = useLexicalComposerContext(); useEffect(() => { - if (handleSubmit) editor.registerCommand(KEY_ENTER_COMMAND, (event) => { - if (event?.ctrlKey) { - handleSubmit(); - return true; - } - return false; - }, 1); + if (handleSubmit) { + return editor.registerCommand(KEY_ENTER_COMMAND, (event) => { + if (event?.ctrlKey) { + handleSubmit(); + return true; + } + return false; + }, 1); + } + }, [handleSubmit]); + + useEffect(() => { editor.registerUpdateListener(({ editorState }) => { const isEmpty = editorState.read(() => $getRoot().getTextContent()) === ''; const data = isEmpty ? null : JSON.stringify(editorState.toJSON());