Skip to content

[lexical-rich-text] Bug Fix: extend adjacent node selections with Shift+Arrow - #9067

Merged
etrepum merged 3 commits into
meta:mainfrom
luantaraschi:fix/node-selection-shift-arrow
Aug 17, 2026
Merged

etrepum merged 3 commits into
meta:mainfrom
luantaraschi:fix/node-selection-shift-arrow

Conversation

@luantaraschi

Copy link
Copy Markdown
Contributor

Description

The arrow-key handlers collapsed a NodeSelection before checking shiftKey, so Shift+Arrow moved the caret away from a selected decorator instead of extending the selection.

This converts a NodeSelection to a RangeSelection when it contains one node or contiguous siblings, then extends the range in the requested direction. Discontiguous node selections keep the existing collapse behavior because a range would also select the nodes between them.

Closes #9062

Test plan

Before

vitest --run packages/lexical-rich-text/src/__tests__/unit/RichTextNodeSelectionArrow.test.ts
Test Files  1 failed (1)
Tests       5 failed | 1 passed (6)

After

vitest --run packages/lexical-rich-text/src/__tests__/unit
Test Files  16 passed (16)
Tests       141 passed (141)

VITEST_BROWSER=chromium,firefox,webkit vitest --project browser --run packages/lexical-rich-text/src/__tests__/browser/RichTextNodeSelectionArrow.test.ts
Test Files  3 passed (3)
Tests       15 passed (15)

TypeScript, ESLint for the changed files, Prettier, and git diff --check also pass.

…ft+Arrow

## Description

The arrow-key handlers collapsed a `NodeSelection` before checking `shiftKey`, so Shift+Arrow moved the caret away from a selected decorator instead of extending the selection.

This converts a `NodeSelection` to a `RangeSelection` when it contains one node or contiguous siblings, then extends the range in the requested direction. Discontiguous node selections keep the existing collapse behavior because a range would also select the nodes between them.

Closes meta#9062

## Test plan

### Before

```text
vitest --run packages/lexical-rich-text/src/__tests__/unit/RichTextNodeSelectionArrow.test.ts
Test Files  1 failed (1)
Tests       5 failed | 1 passed (6)
```

### After

```text
vitest --run packages/lexical-rich-text/src/__tests__/unit
Test Files  16 passed (16)
Tests       141 passed (141)

VITEST_BROWSER=chromium,firefox,webkit vitest --project browser --run packages/lexical-rich-text/src/__tests__/browser/RichTextNodeSelectionArrow.test.ts
Test Files  3 passed (3)
Tests       15 passed (15)
```

TypeScript, ESLint for the changed files, Prettier, and `git diff --check` also pass.
@vercel

vercel Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview Aug 17, 2026 12:39am
lexical-playground Ready Ready Preview Aug 17, 2026 12:39am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 13, 2026
@levensta

Copy link
Copy Markdown
Contributor

If you select a decorator, pressing Shift + ArrowDown once adds the next decorator to the selection, and pressing it a second time deselects everything and moves the cursor to the end of the editor

Screen.Recording.2026-08-17.at.02.56.55.mov

I think the expected behavior would be to select all content starting from the decorator and extending to the end of the editor

@etrepum

etrepum commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

I think that Shift+Arrow should behave exactly as if the original selection was a RangeSelection, so basically the logic is to convert NodeSelection to RangeSelection and then process the event. In the case of a discontiguous NodeSelection it should probably do nothing. I don't think this PR behaves quite correctly.

@etrepum
etrepum added this pull request to the merge queue Aug 17, 2026
Merged via the queue into meta:main with commit 29d4007 Aug 17, 2026
48 checks passed
@etrepum etrepum mentioned this pull request Aug 31, 2026

This branch was successfully deployed

2 active deployments
Preview – lexical — 3b187969 Deployed Aug 17, 2026 by vercel[bot]
Preview – lexical-playground — 3b187969 Deployed Aug 17, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Shift + Arrow does not extend the selection from the NodeSelection

3 participants