[lexical] Bug Fix: Fix selected text not properly deleted after IME input on Safari (macOS)#8154
Conversation
Ensure Safari composition state is properly reset for any key press during composition end, not only backspace, to prevent state leaks
|
Hi @sKawashima! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Description
In Safari on macOS, after confirming IME composition (e.g. Japanese input) with a non-backspace key (Enter, Space, etc.), pressing Backspace to delete a text selection (created via Shift+Arrow or Cmd+A) did not work correctly.
Root cause:
Safari fires
compositionendbeforekeydown(unlike other browsers).isSafariEndingCompositionis set totrueoncompositionendto defer composition finalization to the nextkeydown. However, the flag was only cleared whenkeydownfired with Backspace — leaving it as staletruewhen composition was confirmed with any other key.When the user later pressed Backspace to delete a selection:
$handleKeyDownsawisSafariEndingComposition = trueand called$onCompositionEndImpl$updateTextNodeFromDOMContentcalledselection.setTextNodeRange(anchorNode, anchorOffset, anchorNode, focusOffset), forcing anchor and focus onto the same nodebeforeinput deleteContentBackwardoperated on the wrong selection, producing incorrect deletionFix: When
isSafariEndingCompositionistruebut the key is not Backspace, clear the flag without calling$onCompositionEndImpl. Composition finalization for non-backspace confirmations is already handled by thebeforeinputevent.Closes #8153
Test plan
Before
After typing with Japanese IME and confirming with Enter, selecting all text with Cmd+A and pressing Delete does not delete the selected text correctly.
2026-02-19.21.37.49.mov
After
Deletion works correctly after IME composition confirmed with non-backspace
keys.
2026-02-19.22.10.23.mov