Skip to content

Commit

Permalink
[lexical] Chore: Rename variable and add comments for Safari composit…
Browse files Browse the repository at this point in the history
…ing workaround (#7092)
  • Loading branch information
EruditionTu authored Jan 24, 2025
1 parent 81c9ab6 commit f8e5968
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/lexical/src/LexicalEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ let isSelectionChangeFromDOMUpdate = false;
let isSelectionChangeFromMouseDown = false;
let isInsertLineBreak = false;
let isFirefoxEndingComposition = false;
let isSafariEndComposition = false;
let isSafariEndingComposition = false;
let safariEndCompositionEventData = '';
let collapsedSelectionFormat: [number, string, number, NodeKey, number] = [
0,
Expand Down Expand Up @@ -1009,7 +1009,12 @@ function onCompositionEnd(
if (IS_FIREFOX) {
isFirefoxEndingComposition = true;
} else if (!IS_IOS && (IS_SAFARI || IS_APPLE_WEBKIT)) {
isSafariEndComposition = true;
// Fix:https://github.com/facebook/lexical/pull/7061
// In safari, onCompositionEnd triggers before keydown
// This will cause an extra character to be deleted when exiting the IME
// Therefore, a flag is used to mark that the keydown event is triggered after onCompositionEnd
// Ensure that an extra character is not deleted due to the backspace event being triggered in the keydown event.
isSafariEndingComposition = true;
safariEndCompositionEventData = event.data;
} else {
updateEditorSync(editor, () => {
Expand All @@ -1034,11 +1039,11 @@ function onKeyDown(event: KeyboardEvent, editor: LexicalEditor): void {
if (key == null) {
return;
}
if (isSafariEndComposition && isBackspace(lastKeyCode)) {
if (isSafariEndingComposition && isBackspace(lastKeyCode)) {
updateEditorSync(editor, () => {
$onCompositionEndImpl(editor, safariEndCompositionEventData);
});
isSafariEndComposition = false;
isSafariEndingComposition = false;
safariEndCompositionEventData = '';
return;
}
Expand Down

0 comments on commit f8e5968

Please sign in to comment.