Repository navigation
[lexical-table] Bug Fix: step by the visited cell's colSpan when walking left to insert a column - #8911
Merged
Conversation
…ing left to insert a column
## Description
`$insertTableColumnAtNode` walks leftward through the row map to find the cell
that physically lives in the current row (rather than being projected into it by
an earlier `rowSpan`) so the new cell can be `insertAfter`-ed at the right DOM
position. The invariant is that `prevCellIndex` always sits on the *last* grid
column of the cell currently under examination, so each step must subtract that
cell's `colSpan`.
The loop instead always subtracted `currentCell.__colSpan` — the colSpan of the
cell at the insertion column, which never changes as the walk proceeds. When
that cell is wider than a cell visited later in the walk, the walk jumps over
intervening cells, including cells that do belong to the current row, and the
new cell is inserted in the wrong grid column. The result is a table whose
columns no longer line up across rows.
Stepping by `insertAfterCell.__colSpan` is equivalent on the first iteration
(where `insertAfterCell === currentCell`), so simple tables are unaffected.
## Test plan
### Before
New unit test in `LexicalTableUtils.test.ts` fails on `main`:
```
- Expected
+ Received
[
"A1",
"X",
"C",
"C",
- "",
"D1",
+ "",
],
```
### After
`pnpm run test-unit` for `packages/lexical-table` passes (149 tests).
LeSingh1
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
August 4, 2026 03:42
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
approved these changes
Aug 5, 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
When
$insertTableColumnAtNodewalks leftward to find the cell that physically lives in the current row, it always steps bycurrentCell.__colSpan— the colSpan of the cell at the insertion column, which is fixed for the whole walk:prevCellIndexsits on the last grid column ofinsertAfterCell, so stepping to the column before it means subtracting that cell's colSpan. Using the starting cell's colSpan skips cells whenever the two differ, and the new column is inserted at the wrong grid position — misaligning columns in tables that contain merged cells.This subtracts
insertAfterCell.__colSpaninstead.Introduced in #5546; the line has not been revisited since.
Test plan
Before
New test
walks left by each visited cell colSpan when a row is spannedfails onmain, with the inserted cell landing in the wrong row:After
Passes. Full
packages/lexical-tablesuite: 10 files, 149 tests passed.eslint,prettierandtsc --noEmitclean.