Merge branch 'lexical-ctrl-enter' into 'main'
lexical: fix ctrl+Enter See merge request soapbox-pub/soapbox!2747
This commit is contained in:
commit
d1c2cdecb5
1 changed files with 12 additions and 7 deletions
|
@ -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());
|
||||
|
|
Loading…
Reference in a new issue