Skip to content

Commit

Permalink
[lexical] Bug Fix: In the Safari browser, during the compositing even…
Browse files Browse the repository at this point in the history
…t process, the delete key exhibits unexpected behavior. (#7061)

Co-authored-by: 涂博闻 <[email protected]>
  • Loading branch information
EruditionTu and 涂博闻 authored Jan 18, 2025
1 parent 92a1cd7 commit 46c9c2f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/lexical/src/LexicalEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
'',
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 46c9c2f

Please sign in to comment.