Repository navigation
[lexical-rich-text] Bug Fix: Keep block cursor in editor when ArrowUp at start of root (#8886) - #8887
Conversation
… at start of root (meta#8886) ## Description Current behavior: when a non-inline decorator node is the first child of the document and the block cursor sits before it (a collapsed RangeSelection at root offset 0), pressing ArrowUp again fell through to the browser default. The native selection moved outside the editor, with browser-specific breakage — text entry and paste failing in Chrome, Firefox, and Safari. The ArrowDown handler already guards the bottom boundary with $isSelectionAtEndOfRoot, but the ArrowUp handler had no symmetric top-boundary guard. New behavior: this adds $isSelectionAtStartOfRoot (a mirror of $isSelectionAtEndOfRoot) and a guard at the top of the ArrowUp range-selection branch that calls preventDefault and returns true. At the top of root neither the native selection nor the lexical selection changes, keeping arrow navigation within the editor. Closes meta#8886 ## Test plan ### Before Added a regression test that dispatches KEY_ARROW_UP_COMMAND from a block cursor before a leading decorator. Before the fix the event was not handled (event.defaultPrevented === false), so the browser default moved the native selection out of the editor. ### After New unit test RichTextBlockCursorRootBoundary.test.ts covers both root boundaries (ArrowUp at start, ArrowDown at end): the command is handled, event.defaultPrevented is true, and the block cursor stays in place. Full rich-text unit suite passes (114/114); prettier, eslint, and tsc are clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Fix looks correct and safe to ship — it's a clean mirror of the existing One behavioral nuance worth calling out, plus a few test cases I'd add: shift+ArrowUpThe new guard runs before the shiftKey checks and doesn't test Uncovered cases / test improvementsThe two tests cover the happy path well. Gaps I'd close:
Nit: test filename is consistent with |
Description
Current behavior: when a non-inline decorator node is the first child of the document and the block cursor sits before it (a collapsed RangeSelection at root offset 0), pressing ArrowUp again fell through to the browser default. The native selection moved outside the editor, with browser-specific breakage — text entry and paste failing in Chrome, Firefox, and Safari.
The ArrowDown handler already guards the bottom boundary with $isSelectionAtEndOfRoot, but the ArrowUp handler had no symmetric top-boundary guard.
New behavior: this adds $isSelectionAtStartOfRoot (a mirror of $isSelectionAtEndOfRoot) and a guard at the top of the ArrowUp range-selection branch that calls preventDefault and returns true. At the top of root neither the native selection nor the lexical selection changes, keeping arrow navigation within the editor.
Closes #8886
Test plan
Before
Added a regression test that dispatches KEY_ARROW_UP_COMMAND from a block cursor before a leading decorator. Before the fix the event was not handled (event.defaultPrevented === false), so the browser default moved the native selection out of the editor.
After
New unit test RichTextBlockCursorRootBoundary.test.ts covers both root boundaries (ArrowUp at start, ArrowDown at end): the command is handled, event.defaultPrevented is true, and the block cursor stays in place. Full rich-text unit suite passes (114/114); prettier, eslint, and tsc are clean.