From 5725639588be25503b9a817c7095fc0aaa522194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nicole=20miko=C5=82ajczyk?= Date: Sun, 24 Aug 2025 20:57:02 +0200 Subject: [PATCH] pl-fe: remove just introduced regression MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: nicole mikołajczyk --- .../compose/editor/plugins/state-plugin.tsx | 29 +--------------- .../compose/editor/plugins/submit-plugin.tsx | 33 ++++++++++++++----- 2 files changed, 25 insertions(+), 37 deletions(-) diff --git a/packages/pl-fe/src/features/compose/editor/plugins/state-plugin.tsx b/packages/pl-fe/src/features/compose/editor/plugins/state-plugin.tsx index 35674e7a3..b74a57f84 100644 --- a/packages/pl-fe/src/features/compose/editor/plugins/state-plugin.tsx +++ b/packages/pl-fe/src/features/compose/editor/plugins/state-plugin.tsx @@ -2,8 +2,7 @@ import { HashtagNode } from '@lexical/hashtag'; import { AutoLinkNode, LinkNode } from '@lexical/link'; import { $convertToMarkdownString } from '@lexical/markdown'; import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'; -import { CAN_USE_BEFORE_INPUT, IS_APPLE_WEBKIT, IS_IOS, IS_SAFARI } from '@lexical/utils'; -import { $nodesOfType, $getRoot, type EditorState, $getNodeByKey, KEY_ENTER_COMMAND, $getSelection, $isRangeSelection, INSERT_PARAGRAPH_COMMAND, INSERT_LINE_BREAK_COMMAND, COMMAND_PRIORITY_CRITICAL } from 'lexical'; +import { $nodesOfType, $getRoot, type EditorState, $getNodeByKey } from 'lexical'; import debounce from 'lodash/debounce'; import { useCallback, useEffect } from 'react'; import { useIntl } from 'react-intl'; @@ -164,32 +163,6 @@ const StatePlugin: React.FC = ({ composeId, isWysiwyg }) => { }, 750), []); useEffect(() => { - // Adapted from https://github.com/facebook/lexical/blob/main/packages/lexical-rich-text/src/index.ts#L929 - editor.registerCommand( - KEY_ENTER_COMMAND, - (event) => { - const selection = $getSelection(); - if (!$isRangeSelection(selection)) { - return false; - } - - if (event !== null) { - if ( - (IS_IOS || IS_SAFARI || IS_APPLE_WEBKIT) && - CAN_USE_BEFORE_INPUT - ) { - return false; - } - event.preventDefault(); - if (event.ctrlKey && event.shiftKey) { - return editor.dispatchCommand(INSERT_PARAGRAPH_COMMAND, undefined); - } - } - return editor.dispatchCommand(INSERT_LINE_BREAK_COMMAND, false); - }, - COMMAND_PRIORITY_CRITICAL, - ); - return editor.registerUpdateListener(({ editorState }) => { const plainText = editorState.read(() => $getRoot().getTextContent()); editor.update(() => { diff --git a/packages/pl-fe/src/features/compose/editor/plugins/submit-plugin.tsx b/packages/pl-fe/src/features/compose/editor/plugins/submit-plugin.tsx index c41d3ed59..1faa72e08 100644 --- a/packages/pl-fe/src/features/compose/editor/plugins/submit-plugin.tsx +++ b/packages/pl-fe/src/features/compose/editor/plugins/submit-plugin.tsx @@ -1,5 +1,6 @@ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'; -import { KEY_ENTER_COMMAND } from 'lexical'; +import { CAN_USE_BEFORE_INPUT, IS_APPLE_WEBKIT, IS_IOS, IS_SAFARI } from '@lexical/utils'; +import { $getSelection, $isRangeSelection, INSERT_LINE_BREAK_COMMAND, INSERT_PARAGRAPH_COMMAND, KEY_ENTER_COMMAND } from 'lexical'; import { useEffect } from 'react'; interface ISubmitPlugin { @@ -11,15 +12,29 @@ const SubmitPlugin: React.FC = ({ composeId, handleSubmit }) => { const [editor] = useLexicalComposerContext(); useEffect(() => { - if (handleSubmit) { - return editor.registerCommand(KEY_ENTER_COMMAND, (event) => { - if (event?.ctrlKey) { - handleSubmit(); - return true; - } + // Adapted from https://github.com/facebook/lexical/blob/main/packages/lexical-rich-text/src/index.ts#L929 + return editor.registerCommand(KEY_ENTER_COMMAND, (event) => { + if (handleSubmit && event?.ctrlKey && !event.shiftKey) { + handleSubmit(); + return true; + } + + const selection = $getSelection(); + if (!$isRangeSelection(selection)) { return false; - }, 1); - } + } + + if (event !== null) { + if ((IS_IOS || IS_SAFARI || IS_APPLE_WEBKIT) && CAN_USE_BEFORE_INPUT) { + return false; + } + event.preventDefault(); + if (event.ctrlKey && event.shiftKey) { + return editor.dispatchCommand(INSERT_PARAGRAPH_COMMAND, undefined); + } + } + return editor.dispatchCommand(INSERT_LINE_BREAK_COMMAND, false); + }, 1); }, [handleSubmit]); return null;