From 46c9c2f9d738f974cc9b7cacf7088c168edba78c Mon Sep 17 00:00:00 2001 From: CityHunter <62472294+EruditionTu@users.noreply.github.com> Date: Sat, 18 Jan 2025 13:00:38 +0800 Subject: [PATCH] [lexical] Bug Fix: In the Safari browser, during the compositing event process, the delete key exhibits unexpected behavior. (#7061) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 涂博闻 --- packages/lexical/src/LexicalEvents.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/lexical/src/LexicalEvents.ts b/packages/lexical/src/LexicalEvents.ts index 092e06e6f4d..4a85a6a2939 100644 --- a/packages/lexical/src/LexicalEvents.ts +++ b/packages/lexical/src/LexicalEvents.ts @@ -176,6 +176,8 @@ let isSelectionChangeFromDOMUpdate = false; let isSelectionChangeFromMouseDown = false; let isInsertLineBreak = false; let isFirefoxEndingComposition = false; +let isSafariEndComposition = false; +let safariEndCompositionEventData = ''; let collapsedSelectionFormat: [number, string, number, NodeKey, number] = [ 0, '', @@ -1006,6 +1008,9 @@ function onCompositionEnd( // the logic in onInput. if (IS_FIREFOX) { isFirefoxEndingComposition = true; + } else if (!IS_IOS && (IS_SAFARI || IS_APPLE_WEBKIT)) { + isSafariEndComposition = true; + safariEndCompositionEventData = event.data; } else { updateEditorSync(editor, () => { $onCompositionEndImpl(editor, event.data); @@ -1029,6 +1034,14 @@ function onKeyDown(event: KeyboardEvent, editor: LexicalEditor): void { if (key == null) { return; } + if (isSafariEndComposition && isBackspace(lastKeyCode)) { + updateEditorSync(editor, () => { + $onCompositionEndImpl(editor, safariEndCompositionEventData); + }); + isSafariEndComposition = false; + safariEndCompositionEventData = ''; + return; + } if (isMoveForward(key, ctrlKey, altKey, metaKey)) { dispatchCommand(editor, KEY_ARROW_RIGHT_COMMAND, event);