Repository navigation
[lexical] Bug Fix: Backspace at a soft line-wrap boundary in Firefox - #9101
Merged
etrepum merged 1 commit intoAug 27, 2026
Merged
Conversation
## Description
Where a line soft-wraps, one DOM offset has two visual caret positions — the
end of the wrapped line and the start of the next — and which one the caret
holds is engine state the DOM selection API does not expose. Firefox spends
the first `Selection.modify(alter, 'backward', 'character')` call flipping
between those two positions rather than moving, so it reports the same
boundary point it started from.
`RangeSelection.deleteCharacter` measures a collapsed native caret move to
find the grapheme boundary to delete to. With the caret parked on a wrap
boundary that measurement said the caret had not moved, the model selection
stayed collapsed, and Backspace deleted nothing. Chromium does not reproduce
it; the pre-existing `modify('extend')` measurement was stuck at the same
offset, so this is not a regression from the collapsed-move rework in meta#8766.
`moveNativeSelection` now asks for the movement a second time when, for
`character` granularity only, the boundary point is unchanged *and* the DOM
Text node it sits in still has a code unit on the side being crossed — so a
movement was definitely available and cannot have left that text node. A caret
that genuinely cannot move stays put on the second call too, and non-character
granularities are untouched, where a no-op is meaningful (backward
`lineboundary` from the start of a line).
That guard is sized from a scan of every caret position across 18 fixtures on
both engines, reporting only positions where a first call is consumed:
- Firefox: 14 such positions — space wraps, `word-break: break-all`,
`white-space: normal`, RTL, mixed bidi, emoji and combining marks,
decorator-adjacent wraps, multiple paragraphs. All 14 are interior to a text
node, so the guard admits every one. Fixtures whose wrap lands exactly on a
node boundary have none at all: the two visual positions there already have
two distinct DOM representations, so nothing is ambiguous to flip.
- Chromium: only element points beside an inline decorator, where a second
call does not cross a character but lands on the far side of the decorator.
Chasing that Chromium case down surfaced a second, older bug.
`DecoratorNode.isIsolated()` had no documented behavior for caret movement and
the code supplied none: `$modifySelectionAroundDecoratorsAndBlocks` hops the
caret over an adjacent decorator but declined to for an isolated one and
returned false, leaving the movement to the native measurement. Three
successive `modify('move', backward, 'character')` calls from the element
point between an isolated inline decorator and the text after it:
```
chromium def:0 -> def:0 -> def:0 -> def:0 (trapped; no way past by keyboard)
firefox def:0 -> abc:3 -> abc:2 -> abc:1 (steps over it)
```
Resolve it in the model instead: an adjacent isolated decorator stops the
caret, and the pre-pass reports the movement handled with the selection left
where it is. That matches what `isIsolated()` already means at its other call
sites — `deleteCharacter` refuses to delete such a decorator and
`$isSelectableBlockDecorator` in `@lexical/rich-text` refuses to select one —
and it is now written down on the method, which carried no doc comment at all.
This does change Firefox, which could previously step over an isolated
decorator; there was no defined behavior to preserve, since the engines never
agreed, and the only node in the repo that returns true is the playground's
portal-rendered `StickyNode`, which has no E2E coverage of caret movement.
Closes meta#9100
## Test plan
New browser-mode tests in
`packages/lexical/src/__tests__/browser/Issue9100WrappedLineDeletion.test.ts`.
The first group lays out text in a fixed-width monospace contenteditable so it
soft-wraps, asserts the fixture really does wrap, then deletes backward and
forward from every offset asserting exactly one character goes each time. The
second pins the isolated-decorator behavior on both engines, including that
the native measurement is not consulted for it at all.
### Before
```
$ VITEST_BROWSER=firefox,chromium npx vitest run \
--project 'browser (chromium)' --project 'browser (firefox)' Issue9100
FAIL |browser (chromium)| .../Issue9100WrappedLineDeletion.test.ts > an isolated decorator stops the caret on every engine > the caret does not cross it, and the engine is not asked
AssertionError: expected 'text text:0' to be 'paragraph element:2' // Object.is equality
FAIL |browser (firefox)| .../Issue9100WrappedLineDeletion.test.ts > deletion at a soft line-wrap boundary (meta#9100) > backspace deletes exactly one character at every offset
AssertionError: backspace at offset 10: expected 'aaaa bbbb cccc dddd' to be 'aaaa bbbbcccc dddd' // Object.is equality
FAIL |browser (firefox)| .../Issue9100WrappedLineDeletion.test.ts > an isolated decorator stops the caret on every engine > the caret does not cross it, and the engine is not asked
AssertionError: expected 'text text:1' to be 'paragraph element:2' // Object.is equality
Test Files 2 failed (2)
Tests 3 failed | 5 passed (8)
```
### After
```
$ VITEST_BROWSER=firefox,chromium pnpm run test-browser
Test Files 38 passed (38)
Tests 270 passed | 2 skipped (272)
$ pnpm run test-unit
Test Files 271 passed (271)
Tests 5424 passed | 1 skipped (5425)
$ pnpm run lint && pnpm run ci-check
No errors!
```
WebKit could not be exercised: the Playwright WebKit build fails its host
requirement check in this Linux container. Firefox and Chromium were both run
for the full browser suite above.
Co-Authored-By: Claude <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
marked this pull request as ready for review
August 27, 2026 03:35
etrepum
requested review from
acywatson,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
August 27, 2026 03:35
zurfyx
approved these changes
Aug 27, 2026
unix-max
pushed a commit
to unix-max/lexical
that referenced
this pull request
Aug 28, 2026
…eta#9101) Co-authored-by: Claude <[email protected]>
Merged
This branch was successfully deployed
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
Where a line soft-wraps, one DOM offset has two visual caret positions: the end of the wrapped line, and the start of the next. The DOM selection API does not expose these two positions as distinct points. Firefox spends the first
Selection.modify(alter, 'backward', 'character')call flipping between those two positions rather than moving, when this happens in our "controlled" selection model the caret can get stuck.moveNativeSelectionnow asks for the movement a second time when this condition is detected in a DOM Text node that has more code units in that direction forcharactergranularity.While investigating this issue, a platform inconsistency in
DecoratorNode.isIsolated()behavior was surfaced and made consistent.Closes #9100
Test plan
New browser-mode tests in
packages/lexical/src/__tests__/browser/Issue9100WrappedLineDeletion.test.ts. The first group lays out text in a fixed-width monospace contenteditable so it soft-wraps, asserts the fixture really does wrap, then deletes backward and forward from every offset asserting exactly one character goes each time. The second pins the isolated-decorator behavior on both engines, including that the native measurement is not consulted for it at all.