Bug: [lexical] Line deletion at a soft wrap also removes an inline decorator from the neighbouring visual line
Lexical version: 0.51.0 (the current latest). It reproduces on playground.lexical.dev (0.51.0+dev.esm) in Chromium 153 with the macOS key bindings, in rich and plain text, and the code is unchanged on main at c23a367.
Steps To Reproduce
- In the playground on macOS, type
alpha beta gamma delta, insert an inline equation (Insert → Equation, Inline), then typeepsilon zeta eta theta iota kappa. - Narrow the window until the equation is the first thing on the second visual line of the paragraph.
- Put the caret on the first visual line after
al, and press Cmd+Delete, or Ctrl+K (DELETE_LINE_COMMAND, forward).
Backward: leave no space between the equation and the next word (… delta + equation + epsilon …). Narrow the window until the equation ends the first visual line and epsilon starts the second. Put the caret after eps and press Cmd+Backspace.
Link to code example: the playground steps above. It also reproduces in a plain PlainTextExtension editor with an inline decorator that renders a <span>, in a root about 190px wide, by dispatching DELETE_LINE_COMMAND.
The current behavior
Forward: the rest of the first visual line is deleted, and so is the equation that starts the second: al epsilon zeta ….
Backward: the start of the second visual line is deleted, and so is the equation that ends the first: alpha beta gamma delta ilon ….
It happens with other inline decorators too (a <span>, a <button>), and forward with no space before the decorator. Backward, if a space separates the decorator from the next visual line's first word, the decorator is kept.
deleteLine extends a collapsed selection with $extendSelectionForDeletion(this, isBackward, 'lineboundary') (LexicalSelection.ts#L2114-L2116). That measures the boundary with a native modify('move', …, 'lineboundary'), which stops at the wrap; forward, that is the end of the text node before the equation. The step after it (L2808-L2816) runs $modifySelectionAroundDecoratorsAndBlocks(…, 'lineboundary', 'decorators'). That function walks on over every adjacent inline decorator (L4761-L4775: if (isLineBoundary && origin.isInline()) continue;). #7270 added it to carry a line deletion past inline decorators that the native move stops at. It can't tell those apart from a soft wrap, so it takes the decorator from the next visual line.
The expected behavior
The deletion stops at the visual line boundary the native measurement found. Forward leaves al + equation + epsilon …; backward leaves alpha beta gamma delta + equation + ilon ….
The step after the measurement could skip only the inline decorators on the same visual line as the measured boundary, for example by comparing each decorator's client rect with the landed caret's. I haven't tried it.
Impact of fix
Deleting to the end or start of a wrapped line removes an equation, mention or other inline decorator that the user sees on another line. Where lines wrap depends on the window width, so the same keystroke deletes different content on different screens.
Source: facebook/lexical