[lexical-table] Bug Fix: prepend inserted column cell for rows fully covered by an earlier rowSpan
Description
$insertTableColumnAtNode appended the newly-created cell to the end of a row whenever it couldn't find an "insert after" cell in that row. That branch is reached when every grid column to the left of the insertion point in a given row is covered by a rowSpan from an earlier row — in which case the new cell is actually the row's first real cell and must be prepended, not appended.
As a result, inserting a column into a table that contains a multi-row rowSpan cell placed the new (empty) cell in the wrong grid column for the spanned rows, misaligning the column across the table.
Example
row0: [ A(rowSpan=2) , B ]
row1: [ C ] // grid column 0 is covered by A's rowSpan
Inserting a column after A (grid column 0) should yield an empty cell at grid column 1 in every row. Before this fix, row1's new cell was appended after C, landing in the wrong grid column.
Fix
When the row has no "insert after" cell (all left columns covered by an earlier rowSpan), prepend the new cell with $insertFirst instead of append, so it occupies the row's first grid column position.
Test plan
Added a regression unit test in LexicalTableUtils.test.ts that builds a rowSpan=2 table and asserts the inserted column lines up at grid column 1 in every row (via $getGridTexts). It fails on main (new cell in the wrong column) and passes with the fix. Existing lexical-table unit tests remain green.
The latest updates on your projects. Learn more about Vercel for GitHub.
| Project | Deployment | Actions | Updated (UTC) |
|---|---|---|---|
| lexical | Preview | Jul 15, 2026 1:05am | |
| lexical-playground | Preview | Jul 15, 2026 1:05am |
The fix looks right — $insertFirst matches the existing guard a few lines above (insertAfterColumn < 0) and the $getGridTexts helper makes the column-alignment assertion easy to read. Left a small note on the test pattern inline.