Repository navigation
[lexical-table] Bug Fix: Table alignment fails when selecting in non-TL->BR direction - #8883
Merged
etrepum merged 2 commits intoJul 27, 2026
Merged
Conversation
…en selecting in non-TL->BR direction Current behavior: $isFullTableSelection required selection.anchor to be exactly the top-left cell and selection.focus to be exactly the bottom-right cell. Since $computeTableMap always builds the grid in document order regardless of drag direction, any full-table selection started from a different corner (bottom-right, top-right, or bottom-left) failed this check and silently fell through to per-cell alignment instead of aligning the table itself. Changes in this PR: replaces the corner-key equality check with a direction-agnostic bounding-rectangle check, reusing the min/max span computation the per-cell fallback already had. This also removes the now-redundant $isFullTableSelection helper and its duplicate $computeTableMap call. Closes meta#8880 Verified against current main (82cdae1) both by reverting the fix locally (unit + e2e tests fail exactly on the 3 previously-broken directions) and by reproducing the bug live on playground.lexical.dev.
Removed comments that explained the change relative to the fix/PR (referencing "the bug", "meta#8880", "before the fix") rather than documenting durable behavior for future readers — that context belongs in the commit message, not in code that outlives it.
sahiee-dev
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
July 27, 2026 11:28
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
approved these changes
Jul 27, 2026
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
Current behavior
When a
TableSelectioncovers every cell in a table,FORMAT_ELEMENT_COMMANDis expected to align the table itself instead of aligning the text inside each cell.However, this only worked when the selection started at the top-left cell and ended at the bottom-right cell. The
$isFullTableSelectionhelper compared theanchorandfocusnode keys directly againstmap[0][0]andmap[last][last], so it only recognised selections made in that specific direction.Since
$computeTableMapalways builds the table grid in document order, regardless of where the drag starts, full-table selections made in the other three directions (bottom-right → top-left, top-right → bottom-left, and bottom-left → top-right) failed this check.As a result, those selections incorrectly fell back to per-cell alignment. The text inside each cell was aligned, but the table itself never moved.
Changes in this PR
This PR replaces the corner-based key comparison with a direction-independent bounding rectangle check. It reuses the existing min/max row and column span calculation that the per-cell fallback path already performs.
A selection is now treated as a full-table selection whenever its bounding rectangle spans from
[0,0]to[lastRow,lastCol], regardless of which corner the user starts or ends the drag from.Since this logic makes
$isFullTableSelectionunnecessary, the helper has been removed along with its extra$computeTableMapcall.Closes #8880
Test plan
Before
Result: The text inside each cell is centred, but the table itself is not centred on the page.
Screen.Recording.2026-07-27.at.4.54.27.PM.mov
After
Repeat the same steps.
Result: The table itself is centred on the page, while the text inside the cells remains unchanged. Alignment now behaves the same regardless of which corner the selection starts from.
Screen.Recording.2026-07-27.at.4.55.33.PM.mov
Regression coverage has been added at both levels:
Unit (
packages/lexical-table/src/__tests__/unit/LexicalTableExtension.test.ts)E2E (
packages/lexical-playground/__tests__/e2e/Tables.spec.mjs)<table>receives the alignment class and that no cell paragraph receives an inlinetext-alignstyle.The full unit test suite (226 files, 4,923 tests) and the complete
Tables.spec.mjsE2E suite (88 tests) pass without any regressions.