lexical: fix ctrl+Enter

This commit is contained in:
Alex Gleason 2023-09-23 16:20:09 -05:00
parent 6c318a02ef
commit bc3662afc7
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -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());