Repository navigation
[lexical] Bug Fix: Don't move the caret past the acceptance boundary for Enter on iOS - #8941
Merged
etrepum merged 2 commits intoAug 9, 2026
Merged
Conversation
…for Enter on iOS $maybeMoveSelectionPastTrailingAcceptanceBoundary compensates for Chrome and Firefox, which fire the input event for the key press that triggered a text replacement *before* the one for the replacement text, leaving the caret before the acceptance boundary. iOS fires them in the opposite order — insertReplacementText first, then insertParagraph. The paragraph has not been split yet at that point, so the block the caret sits in still has its original next sibling. The correction moves the caret into that block and the following insertParagraph splits it instead, leaving the caret one block further down than a single Enter should have taken it. This only reproduces when the paragraph has a following sibling block; with nothing after it getNextSibling() is null and the correction is a no-op, which is likely why it went unnoticed. Skip the Enter branch on iOS. Desktop WebKit keeps the correction, so the existing webkit coverage in Events.spec.mjs still passes — guarding on IS_APPLE_WEBKIT instead fails it. Adds IosEnterAcceptanceBoundary.test.ts, which mocks IS_IOS following the existing pattern in IosKeyboardSuggestions.test.ts and dispatches the events in the order iOS produces them. It fails without this change. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
SujinKim1127
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
August 7, 2026 00:48
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@SujinKim1127 is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
ivailop7
approved these changes
Aug 8, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
On iOS, accepting an autocorrect suggestion with Enter moves the caret one
block further than the single Enter should have taken it.
$maybeMoveSelectionPastTrailingAcceptanceBoundaryexists because, as its comment says,Chrome and Firefox fire the input event for the key press that triggered the acceptance
before the one for the replacement text, leaving the caret before the acceptance
boundary.
iOS fires them in the opposite order:
Because the replacement is handled first, the paragraph has not been split yet, so
block.getNextSibling()still returns the block that already followed. The correctionmoves the caret into that block, and the
insertParagraphthat arrives next splitsit instead.
Note that the resulting block structure is the same either way — exactly one paragraph is
inserted. Only the caret position differs, which is why this is easy to miss.
This only reproduces when the paragraph has a following sibling block — with nothing
after it
getNextSibling()isnulland the correction is a no-op, which is likely whyit went unnoticed.
This PR skips the
'\n'branch on iOS. Desktop WebKit keeps the correction, so theexisting webkit coverage in
Events.spec.mjsstill passes — note that guarding onIS_APPLE_WEBKITinstead does fail that test, since it asserts the correction fires onwebkit.
Test plan
Reproduced on an iPhone 17 simulator (iOS 26.1), Safari, software keyboard:
abcin a paragraph that has another paragraph below itBefore
Simulator.Screen.Recording.-.iPhone.17.-.2026-08-06.at.15.34.04.mov
The caret skips the paragraph that was just inserted and lands at the start of the block
that already followed, so it ends up two lines below the text instead of one.
After
Simulator.Screen.Recording.-.iPhone.17.-.2026-08-07.at.09.22.04.mov
The caret stays in the newly inserted paragraph, directly below the text.
Automated
Adds
packages/lexical/src/__tests__/unit/IosEnterAcceptanceBoundary.test.ts, whichmocks
IS_IOSand dispatches the events in the order iOS produces them. It follows thesame
vi.mock('lexical/src/environment')pattern already used for browser-specificfixes in
LexicalEvents.ts(#8769, #8680, #8475, #8725).Two cases:
following block instead of the new paragraph)
where the correction was already a no-op
Happy to move the test somewhere else or restructure it if you'd prefer different
coverage here.