lexical: fix ctrl+Enter
This commit is contained in:
parent
6c318a02ef
commit
bc3662afc7
1 changed files with 12 additions and 7 deletions
|
@ -15,13 +15,18 @@ const StatePlugin = ({ composeId, handleSubmit }: IStatePlugin) => {
|
||||||
const [editor] = useLexicalComposerContext();
|
const [editor] = useLexicalComposerContext();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (handleSubmit) editor.registerCommand(KEY_ENTER_COMMAND, (event) => {
|
if (handleSubmit) {
|
||||||
if (event?.ctrlKey) {
|
return editor.registerCommand(KEY_ENTER_COMMAND, (event) => {
|
||||||
handleSubmit();
|
if (event?.ctrlKey) {
|
||||||
return true;
|
handleSubmit();
|
||||||
}
|
return true;
|
||||||
return false;
|
}
|
||||||
}, 1);
|
return false;
|
||||||
|
}, 1);
|
||||||
|
}
|
||||||
|
}, [handleSubmit]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
editor.registerUpdateListener(({ editorState }) => {
|
editor.registerUpdateListener(({ editorState }) => {
|
||||||
const isEmpty = editorState.read(() => $getRoot().getTextContent()) === '';
|
const isEmpty = editorState.read(() => $getRoot().getTextContent()) === '';
|
||||||
const data = isEmpty ? null : JSON.stringify(editorState.toJSON());
|
const data = isEmpty ? null : JSON.stringify(editorState.toJSON());
|
||||||
|
|
Loading…
Reference in a new issue