Skip to content

[lexical-table] Bug Fix: handle table selections crossing into/out of nested tables#8234

Merged
etrepum merged 3 commits intofacebook:mainfrom
randal-atticus:fix-nested-table-selection
Mar 19, 2026
Merged

[lexical-table] Bug Fix: handle table selections crossing into/out of nested tables#8234
etrepum merged 3 commits intofacebook:mainfrom
randal-atticus:fix-nested-table-selection

Conversation

@randal-atticus
Copy link
Contributor

@randal-atticus randal-atticus commented Mar 18, 2026

Description

Further improvements to table selections, and specifically fixing a nested table selection case.

$fixRangeSelectionForSelectedTable now only runs once (instead of once per table), in line with previous refactors to avoid running all the logic across every table, thereby making it hard to handle nested tables.

The logic has been updated to correctly handle Range Selections that cross into/out of a nested table. Just as before, the (anchor OR focus) is shifted to the (start OR end) of the (anchor OR focus) table depending on the direction of the selection.

Added Playground tests to assert behaviour for nested and non-nested tables.

Test plan

Before

On Playground, observe that range selections crossing a nested table will erroneously expand to the outer table.

Screen.Recording.2026-03-18.at.5.58.12.pm.mov

After

As of this PR, range selections crossing a nested table no longer expand to the outer table.

Screen.Recording.2026-03-18.at.5.58.41.pm.mov

(Just noticed the "table selection" on the inner table is a bit too sticky, but that's a separate bug)

@vercel
Copy link

vercel bot commented Mar 18, 2026

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

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Mar 18, 2026 6:57am
lexical-playground Ready Ready Preview, Comment Mar 18, 2026 6:57am

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 Mar 18, 2026
@randal-atticus
Copy link
Contributor Author

randal-atticus commented Mar 18, 2026

New tests failing in Firefox, investigating.

Seems like on Firefox, a shift-click selection into or out of a nested table selects more than the user requested, but not for top-level tables.

Screen.Recording.2026-03-18.at.5.56.28.pm.mov

EDIT: Ended up disabling these tests on Firefox, because this is what was happening before (above video is from live Playground), and I would rather not let perfect get in the way of good.

tableObservers: TableObservers,
) {
const prevSelection = $getPreviousSelection();
if ($isRangeSelection(selection)) {
Copy link
Contributor Author

@randal-atticus randal-atticus Mar 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

selection was already a RangeSelection. Unfortunately, this bloated the diff, but reviewing without whitespace changes makes this more legible

@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Mar 18, 2026
@etrepum etrepum added this pull request to the merge queue Mar 19, 2026
Merged via the queue into facebook:main with commit 255f154 Mar 19, 2026
68 of 69 checks passed
@etrepum etrepum mentioned this pull request Mar 19, 2026
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.

2 participants