Skip to content

[lexical-table] Bug Fix: step by the visited cell's colSpan when walking left to insert a column - #8911

Merged
etrepum merged 1 commit into
meta:mainfrom
LeSingh1:fix/table-insert-column-colspan-walk
Aug 5, 2026
Merged

etrepum merged 1 commit into
meta:mainfrom
LeSingh1:fix/table-insert-column-colspan-walk

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Description

When $insertTableColumnAtNode walks leftward to find the cell that physically lives in the current row, it always steps by currentCell.__colSpan — the colSpan of the cell at the insertion column, which is fixed for the whole walk:

prevCellIndex -= currentCell.__colSpan;

prevCellIndex sits on the last grid column of insertAfterCell, 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.__colSpan instead.

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 spanned fails on main, with the inserted cell landing in the wrong row:

- Expected
+ Received
     ["A1", "X", "C", "C",
-     "",
      "D1",
+     "",
     ],

After

Passes. Full packages/lexical-table suite: 10 files, 149 tests passed. eslint, prettier and tsc --noEmit clean.

…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).
@vercel

vercel Bot commented Aug 4, 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 4, 2026 3:44am
lexical-playground Ready Ready Preview Aug 4, 2026 3:44am

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 4, 2026
@etrepum
etrepum added this pull request to the merge queue Aug 5, 2026
Merged via the queue into meta:main with commit 359c086 Aug 5, 2026
44 checks passed
@etrepum etrepum mentioned this pull request Aug 31, 2026

This branch was successfully deployed

2 active deployments
Preview – lexical — 368c1777 Deployed Aug 4, 2026 by vercel[bot]
Preview – lexical-playground — 368c1777 Deployed Aug 4, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants