Repository navigation
[lexical-table][lexical-playground][lexical-rich-text] Bug Fix: table grid indices, cell state and boundary selection - #9054
Conversation
|
@LeSingh1 is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
… grid indices, cell state and boundary selection ## Description Eleven small table bugs, consolidated into one branch per the review feedback on meta#9027 and meta#9035. They fall into three groups. ### 1. Grid geometry Code that uses a row's child index where the table *grid* column index is required, or that ignores a span. These agree only while every cell has `colSpan === 1`/`rowSpan === 1`, so they are invisible until a table has merged cells. - `$insertTableColumnAtNode` (`packages/lexical-table/src/LexicalTableUtils.ts`) walked leftwards from the insertion column looking for the cell to insert after. When every grid position at or before the insertion column is covered by a `rowSpan` from an earlier row, the walk fell off the left edge and appended the new cell to the *end* of the row, so the inserted column did not line up. Replaced with the same left-to-right map scan `$unmergeCellNode` uses: track the last row-map entry with `startRow === i` at or before the insertion column, `insertAfter` it, or `$insertFirst` when the row owns nothing to the left. This also removes the labeled `continue`. (meta#8836) - `toggleTableColumnIsHeader` (`packages/lexical-playground/src/plugins/TableActionMenuPlugin/index.tsx`) fed `$setTableColumnIsHeader`, which indexes `gridMap[row][columnIndex]`, the result of `$getTableColumnIndexFromTableCellNode` — the cell's index among its row's *children*. With an earlier spanning cell in the row, "Toggle column header" applied to a column left of the one clicked. It now reads `cellMap.startColumn` from `$computeTableMap`. (meta#9006) ### 2. Cell and table state Transforms that rebuild a cell or its paragraph and drop what it carried, plus the `dir` attribute being written onto an element that the export throws away. - `$insertTableIntoGrid` (`LexicalTableUtils.ts`) copies the template cell's `backgroundColor` onto the destination cell but not `verticalAlign`, which was added to `TableCellNode` after that loop (meta#7077). Pasting a table with vertically aligned cells over an existing table dropped the alignment. (meta#9015) - `$tableTransform` (`LexicalTablePluginHelpers.ts`) pads short rows out to the table width with `$createTableCellNode()` and no header state, so a short header row was repaired into a mix of `<th>` and `<td>`. The padding cells now inherit the `TableCellHeaderStates.ROW` bit from the row's last cell — the same reference `$insertTableColumnAtNode` uses when it appends a column. (meta#9023) - `$unmergeCellNode` (`LexicalTableUtils.ts`) recomputes the header state of the cells it splits off, correctly, but gives them nothing else, so a filled merged cell unmerged into one filled cell and a run of blank ones. The split cells now keep the original's `backgroundColor` and `verticalAlign`, which is the cell's own presentation and not a description of its row or column. (meta#9025) - `TableNode.exportDOM` (`LexicalTableNode.ts`) narrows the export to `element.querySelector('table')`. When scrollable tables are active `createDOM` returns the scroll wrapper `<div>`, which is where `ElementNode.exportDOM` writes `dir` — so the wrapper, and the direction with it, was thrown away. The direction is now re-applied to the `<table>`, which is where `$convertTableElement` reads it back. (meta#9029) - `TableObserver.$clearText` (`LexicalTableObserver.ts`) emptied each selected cell by constructing a fresh `ParagraphNode`, so Backspace over a multi-cell selection also reset the format, style, direction and indent of those cells. It now `$copyNode`s the cell's existing paragraph, which carries the element state and returns a childless copy. (meta#9041) ### 3. Selection and caret at the table boundary - The `KEY_ARROW_LEFT_COMMAND`/`KEY_ARROW_RIGHT_COMMAND` handlers in `registerRichText` (`packages/lexical-rich-text/src/index.ts`) had no equivalent of the `$isSelectionAtEndOfRoot`/`$isSelectionAtStartOfRoot` guards the up/down handlers already use. With a table as the last node of the document the key fell through to the native caret, which walks around the block cursor element, so the caret cycled: last cell → block cursor → root offset before the table → back into the last cell. A new `$isBlockCursorAtRootEdge` consumes the key when the collapsed element point sits at the root edge beside a child that needs a block cursor. Non-collapsed selections and block cursors that still have a sibling to move into are untouched. (meta#8949, fixes meta#7999) - `$handleArrowKey` (`LexicalTableSelectionHelpers.ts`) armed the Firefox scrollable-table workaround (`setShouldCheckSelectionForTable`) on every ArrowDown. From the block cursor below a trailing table ArrowDown moves nothing, so the flag survived to be consumed by the next selection change — an ArrowUp back into the table — which snapped the caret to the first cell. A new `$isSelectionBeforeTable` arms it only when the focus is before the table in document order, the only side ArrowDown can enter from. (meta#8963, fixes meta#6822) - `$deleteTableRowAtSelection` (`LexicalTableUtils.ts`) removes the table outright when the selection covers every row, but never moved the selection first, leaving a `TableSelection` anchored to detached nodes. Added the `grid.selectPrevious()` that `$deleteTableColumnAtSelection` and `TableObserver.$clearText` already do in their identical branches. (meta#9037) - `$adjustFocusInDirection` (`LexicalTableSelectionHelpers.ts`) called `getCornerOrThrow` on the rect from `$computeTableCellRectBoundary`, which *grows* the rect until it contains every merged cell straddling an edge — so the anchor is not guaranteed to be at a corner, and Shift+Arrow killed the editor update with an invariant. `getCornerOrThrow` is replaced by `getAnchorCorner`, which falls back the same way `$extractRectCorners` 24 lines below already does: to the corner opposite the focus, then to the top-left. (meta#9045) ## Test plan Unit tests cover ten of the eleven fixes, two browser tests cover the caret/arrow-key behaviour at the table boundary, and meta#9006 is a Playwright spec (`packages/lexical-playground/__tests__/regression/7266-column-header-merged-cells.spec.mjs`). ### Before Source fixes reverted, new tests kept: ``` $ npx vitest run --project unit packages/lexical-table packages/lexical-rich-text × pasting a table carries the cell backgroundColor and verticalAlign 6ms × a short header row is padded with header cells 5ms × extends the selection instead of throwing 73ms × keeps the paragraph format, style and direction of each cell 89ms × inserts the new cell in the correct column for rows spanned by a rowSpan cell 7ms × exports dir with scrollable tables active 31ms × leaves the selection outside the removed table 13ms × ArrowRight at the block cursor after the last block stays put 5ms × ArrowLeft at the block cursor before the first block stays put 1ms × the cells a merged cell splits into keep its backgroundColor and verticalAlign 13ms ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 10 ⎯⎯⎯⎯⎯⎯⎯ Test Files 8 failed | 23 passed (31) Tests 10 failed | 291 passed (301) $ npx vitest run --project browser packages/lexical-table/src/__tests__/browser/TableTrailingCaret.test.ts packages/lexical-table/src/__tests__/browser/Issue6822BlockCursorArrowKeys.test.ts × the caret stops beneath a trailing table instead of cycling around it 172ms × ArrowUp from the block cursor below a trailing table returns to the last row 380ms × ArrowUp from the block cursor below a table that is the only root child returns to the last row 355ms Test Files 2 failed (2) Tests 3 failed | 2 passed (5) ``` The remaining new cases pass on both sides of the change — the unstyled-unmerge, short-body-row, non-wrapped-export, delete-every-column and still-owns-a-cell-to-the-left cases — which is what pins each asymmetry rather than the fix itself. ### After ``` $ npx vitest run --project unit packages/lexical-table packages/lexical-rich-text Test Files 31 passed (31) Tests 301 passed (301) $ npx vitest run --project browser packages/lexical-table/src/__tests__/browser/TableTrailingCaret.test.ts packages/lexical-table/src/__tests__/browser/Issue6822BlockCursorArrowKeys.test.ts Test Files 2 passed (2) Tests 5 passed (5) $ npx playwright test --project=chromium Tables.spec.mjs TablesHTMLCopyAndPaste.spec.mjs 7266-column-header-merged-cells.spec.mjs 99 passed, 1 skipped $ npx tsc --noEmit -p . (clean) ``` Supersedes meta#8836, meta#8949, meta#8963, meta#9006, meta#9015, meta#9023, meta#9025, meta#9029, meta#9037, meta#9041, meta#9045, consolidated per the review feedback on meta#9027 and meta#9035. meta#9000 and meta#9011 were part of an earlier revision of this PR and have been dropped, because each contradicted an existing e2e expectation rather than extending it: - meta#9000 imported `dir` in the `DOMImportExtension` table rules. Google Sheets emits `<table dir="ltr">` unconditionally, so `Copy + paste (Table - Google Sheets)` in `TablesHTMLCopyAndPaste.spec.mjs` went from `dir="auto"` to a pinned `dir="ltr"` on the table, and the rows below it stopped emitting `dir="auto"` at all. Honouring a pasted `dir` is a deliberate behaviour change for third-party HTML and needs its own PR. - meta#9011 made the right-edge resizer widen the *last* grid column a merged cell spans instead of its first. `Resize merged cells width (2)` in `Tables.spec.mjs` pins the existing behaviour, and both variants widen the merged cell identically — they differ only in which unmerged column absorbs the change, so this is a behaviour preference that needs a maintainer call.
939cae7 to
f3976c1
Compare
|
e2e was red on
I dropped both. Each is a deliberate behaviour change that contradicts an already-merged expectation, so it wants its own PR and a call from you rather than a silent ride-along here. I also removed a stray The remaining eleven members are unchanged. Verified locally: |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…054-review-t5gagd
…e caret cannot leave a table ## Description `Issue6822BlockCursorArrowKeys.test.ts` drives the block cursor beside a table with real arrow keys, and every step it makes is native caret movement — Lexical only imports the result through its selectionchange listener. Gecko never performs that movement: from the last cell of a trailing table an ArrowDown leaves the caret on the table element, and no further arrow press moves it in or out. All three tests therefore failed on the `firefox` browser job at the first `expect(hasBlockCursor(editor)).toBe(true)`, while passing on `chromium`. The suite now asks the engine itself whether a downward line move escapes a trailing table, using a scratch contenteditable outside of Lexical, and skips when it does not. Probing the capability rather than matching a user agent keeps the tests running on any engine that does move the caret, and an engine without `Selection.modify` to probe with runs them rather than skipping silently. ## Test plan ### Before ``` $ VITEST_BROWSER=firefox npx vitest --project browser --no-watch packages/lexical-table/src/__tests__/browser FAIL |browser (firefox)| .../Issue6822BlockCursorArrowKeys.test.ts > block cursor beside a table (meta#6822) > ArrowUp from the block cursor below a trailing table returns to the last row AssertionError: expected false to be true // Object.is equality ❯ .../Issue6822BlockCursorArrowKeys.test.ts:159:35 FAIL |browser (firefox)| .../Issue6822BlockCursorArrowKeys.test.ts > block cursor beside a table (meta#6822) > ArrowUp from the block cursor below a table that is the only root child returns to the last row AssertionError: expected false to be true // Object.is equality ❯ .../Issue6822BlockCursorArrowKeys.test.ts:195:35 FAIL |browser (firefox)| .../Issue6822BlockCursorArrowKeys.test.ts > block cursor beside a table (meta#6822) > ArrowDown from the block cursor above a leading table still enters the first cell AssertionError: expected false to be true // Object.is equality ❯ .../Issue6822BlockCursorArrowKeys.test.ts:222:35 Test Files 1 failed | 2 passed (3) Tests 3 failed | 6 passed (9) ``` ### After ``` $ VITEST_BROWSER=firefox npx vitest --project browser --no-watch Test Files 21 passed | 1 skipped (22) Tests 140 passed | 4 skipped (144) $ VITEST_BROWSER=chromium npx vitest --project browser --no-watch Test Files 22 passed (22) Tests 143 passed | 1 skipped (144) ``` WebKit could not be exercised: the playwright webkit build refuses to launch in this container for want of system libraries, so the probe's behaviour there is untested. It gates on the engine's own answer rather than on a user agent, so whichever way WebKit moves the caret, the suite either runs or skips rather than failing.
…formatting, export keeps the table's indent ## Description Follow-up to the review of meta#9054, covering the two behaviours the branch left half-fixed and three cleanups around them. `$unmergeCellNode` now builds the split cells with `$copyNode` instead of hand-copying two fields onto a fresh `$createTableCellNode`. It previously carried `backgroundColor` and `verticalAlign` but not the `format`, `style`, `direction` or `indent` the cell holds as an ElementNode, so one unmerge produced cells that disagreed with each other: the original kept its formatting and the cells split off it did not. `$copyNode` carries all of it and preserves a `TableCellNode` subclass. Only the state that describes a position rather than the cell is reset — the spans, the header state, and the width, which measured a cell `colSpan` grid columns wide and which every other path that creates a cell in this file already leaves to the table's `colWidths`. `TableNode.exportDOM` recovered `dir` from the scroll wrapper but not the indent. `ElementNode.exportDOM` writes three things onto whatever `createDOM` returned — `dir`, `style.paddingInlineStart` and `data-lexical-indent` — and with scrollable tables active all three land on a wrapper the export discards, so an indented table exported without its indent. It now moves all three onto the `<table>`. Moving rather than re-deriving keeps this in step with whatever `ElementNode.exportDOM` writes next; `createDOM` puts nothing of its own on a wrapper, so anything found there came from the super call. Alongside those: - `$extractRectCorners` now resolves its corner through `getAnchorCorner`. Its three branches were that function inlined — anchor corner, else the corner opposite the focus, else top-left — so the two can no longer drift. The `TODO` about the arbitrary last fallback moves with the logic. - `ShiftArrowOffCornerAnchor` asserted only that the arrow key did not throw, which a wrong-but-valid focus would have satisfied. It now pins the rect the fallback picks. - `RichTextBlockCursorRootBoundary` gains the collapsed-plus-shift cases at both root edges, plus the inward direction that must stay unconsumed, since `$isBlockCursorAtRootEdge` is evaluated before the `!event.shiftKey` guard that gates `$tryBlockCursorShadowRootNavigation`. - `TableExportDirection.test.ts` is renamed to `TableExportAttributes.test.ts`, which is what it now covers. ## Test plan ### Before `$unmergeCellNode` on a merged cell carrying `format: 'center'` and `style: 'color: red;'`, reading back every cell of the split: ``` [{format: 'center', style: 'color: red;'}, // the original cell {format: '', style: ''}] // the cell split off it ``` `TableNode.exportDOM` with `hasHorizontalScroll` on, for a table at indent 2: ``` $ npx vitest --project unit --no-watch packages/lexical-table/src/__tests__/unit/TableExportAttributes.test.ts × exports the indent with scrollable tables active 19ms Expected: "data-lexical-indent="2"" Received: "<table><tbody><tr><td style="border: 1px solid black; width: 75px; vertical-align: top; text-align: start;"><p><br></p></td></tr></tbody></table>" Tests 1 failed | 4 passed (5) ``` ### After ``` $ pnpm run test-unit Test Files 290 passed (290) Tests 5518 passed | 1 skipped (5519) $ pnpm run ci-check CI-CHECK EXIT=0 $ VITEST_BROWSER=chromium npx vitest --project browser --no-watch Test Files 22 passed (22) Tests 143 passed | 1 skipped (144) $ VITEST_BROWSER=firefox npx vitest --project browser --no-watch Test Files 21 passed | 1 skipped (22) Tests 140 passed | 4 skipped (144) ``` A first attempt at the unmerge fix let `$copyNode` carry `__width` through to vertically split cells, which changed the exported HTML and failed `Tables › Can paste table containing merged cells into table`. With the width reset unconditionally: ``` $ npx playwright test --project=chromium packages/lexical-playground/__tests__/e2e/Tables.spec.mjs -g "Can paste table containing merged cells into table" ✓ 1 [chromium] › Tables › Can paste table containing merged cells into table (15.7s) 1 passed (17.1s) ``` The full Chromium e2e sweep is still running at the time of this commit; the run before these changes was 776 passed, 31 skipped. WebKit was not exercised: its Playwright build will not launch in this container for want of system libraries.
…054-review-t5gagd
## Description
Playwright was pinned at `^1.60.0`, whose browser set includes `webkit-2287`.
That WebKit build has been segfaulting its content process on the macOS e2e
jobs, taking the page down mid-test:
```
[pid=15242][err] pw_run.sh: line 7: 15258 Segmentation fault: 11
Error: mouse.click: Target page, context or browser has been closed
```
Nothing in the test code causes that — it is the browser process dying — so
this moves to the current stable release and the browser builds that come with
it:
| browser | 1.60.0 | 1.62.1 |
| --- | --- | --- |
| webkit | 2287 | 2336 |
| firefox | 1522 | 1538 |
| chromium | 1223 | 1234 |
All eight pins move together — the root, `dev-examples/shadow-dom`,
`dev-examples/shadow-dom-web-component`, `examples/nextjs-code-shiki`,
`examples/extension-sveltekit-ssr-hydration` and the astro integration
fixture — so the monorepo resolves to one Playwright and downloads one browser
set. Nothing else needs to change for CI: `setup-playwright` derives its cache
key from `pnpm-lock.yaml` and installs with `pnpm exec playwright install`, so
both the key and the downloaded revisions follow the lockfile.
Note that the 1.61 and 1.62 release notes do not claim a fix for this crash;
the newer WebKit build is the remedy available, not a documented one.
## Test plan
### Before
```
$ pnpm exec playwright --version
Version 1.60.0
$ node -e "const b=require('playwright-core/browsers.json');console.log(b.browsers.filter(x=>x.name==='webkit')[0].revision)"
2287
```
### After
```
$ pnpm exec playwright --version
Version 1.62.1
$ node -e "const b=require('playwright-core/browsers.json');console.log(b.browsers.filter(x=>x.name==='webkit')[0].revision)"
2336
$ pnpm run ci-check
CI-CHECK EXIT=0
$ pnpm run test-unit
Test Files 294 passed (294)
Tests 5547 passed | 1 skipped (5548)
$ VITEST_BROWSER=chromium npx vitest --project browser --no-watch
Test Files 22 passed (22)
Tests 143 passed | 1 skipped (144)
$ VITEST_BROWSER=firefox npx vitest --project browser --no-watch
Test Files 21 passed | 1 skipped (22)
Tests 140 passed | 4 skipped (144)
```
The Chromium e2e sweep is still running at the time of this commit; the run on
1.60.0 before this change was 826 passed, 31 skipped.
WebKit could not be exercised: its Playwright build does not launch in this
container for want of system libraries, and the crash this addresses is on
macOS in any case, so only CI can confirm it is gone.
…of Google Fonts ## Description `index.css` opened with `@import 'https://fonts.googleapis.com/css?family=Reenie+Beanie'`, for a font used by exactly one rule — the sticky note. A third-party stylesheet in the critical path holds the document's `load` event on whatever the network does that day, and it hands a request from every visitor to a third party. The font now ships with the app: `ReenieBeanie-Regular.woff2` in `src/fonts/`, referenced by a local `@font-face` with the same relative `url()` mechanism `index.css` already uses for `images/logo.svg`. It is the official Google Fonts release converted from TTF to woff2 (140KB -> 39KB), and `OFL.txt` travels with it as the SIL Open Font License 1.1 requires. Two details beyond the swap: `font-display: swap`, since the sticky note is decorative and should paint immediately in the fallback; and a `cursive` fallback on the rule itself, which previously named the family with nothing behind it. This also unblocks e2e on a sandboxed network. Where outbound connections are blackholed, Firefox hangs the font request and `load` never fires, so every `initialize()` fails with a `page.goto` timeout: ``` TimeoutError: page.goto: Timeout 30000ms exceeded. - navigating to "http://localhost:3000/?isRichText=true&...", waiting until "load" at packages/lexical-playground/__tests__/utils/index.mjs:187 ``` ## Test plan ### Before Navigating to the playground in Firefox, listing requests still in flight when `load` times out: ``` LOAD FAILED: page.goto: Timeout 25000ms exceeded. --- still pending --- https://fonts.googleapis.com/css?family=Reenie+Beanie http://localhost:3000/apple-touch-icon.png http://localhost:3000/favicon-16x16.png ``` ### After ``` LOAD OK in 3239 ms external requests: [ 'https://va.vercel-scripts.com/v1/script.debug.js', 'https://va.vercel-scripts.com/v1/speed-insights/script.debug.js' ] font requests: (none) ``` The face loads from the app and renders with its own metrics, not the fallback's — a bogus family name measures identically to `cursive`, so the difference is the real font: ``` font file responses: [ '200 /src/fonts/ReenieBeanie-Regular.woff2' ] { bogusEqualsFallback: true, fallback: 284, withFont: 185 } PASS: Reenie Beanie renders with its own metrics, distinct from the fallback ``` The production build emits and rewrites the asset: ``` $ pnpm run build && (cd packages/lexical-playground && npx vite build) ✓ built in 41.54s $ find packages/lexical-playground/build -iname "ReenieBeanie*" packages/lexical-playground/build/assets/ReenieBeanie-Regular-DP68XtsV.woff2 $ grep -oh "assets/ReenieBeanie[^)]*" packages/lexical-playground/build/assets/*.css assets/ReenieBeanie-Regular-DP68XtsV.woff2 ```
…sted table keeps the anchor on Firefox
## Description
A shift-click only ever moves the focus — the anchor is wherever the selection
started. On Firefox it did not: shift-clicking from the cell around a nested
table into that table reset the anchor to the start of the outer cell, so the
selection ran from the top of the cell instead of from the caret.
`$handleTableClick` already has a Firefox workaround for exactly this ("We
can't trust Firefox to do the right thing with the selection"), and its `else`
branch already does the right thing — put the focus at the near edge of the
table, then restore the previous anchor. Two things kept it from running:
- It was gated on `$isSelectionInTable(prevSelection, tableNode)`. Only the
nearest cell's observer is handed the pointerdown, since
`getTableObserverFromCellNode` resolves a single one, so clicking into a
nested table arrives with `tableNode` set to the *inner* table while the
previous selection sits in the outer cell around it. That fails the check,
and the case was left to Firefox. The two inner branches already tell apart
"anchor is in a cell of this table" from "anchor is outside it", so the outer
guard only has to establish that there is a previous range to extend from.
- The `else` branch never called `stopEvent`, unlike the branch above it, so
the native shift-click still ran and the selectionchange import overwrote the
selection that had just been computed.
Firefox 153 (playwright 1.62.1) made this visible; the same reset was already
recorded on Firefox 150 as a `test.fixme` on the sibling case, which this fixes
too, so that test is un-skipped.
The reverse direction — anchor *inside* the nested table, shift-clicking out to
text around it — is still wrong on Firefox and keeps its two `test.fixme`s.
Also in this change: `Selection.spec.mjs` dragged out of a table with a single
`page.mouse.move(500, 500)`. A real drag emits a stream of mousemove events,
and Firefox 153 no longer resolves a single jump as one, so the drag never
became a table selection. It now asks playwright for the intermediate moves.
That is the test being unrealistic rather than a product regression, so no
source change goes with it.
## Test plan
### Before
On playwright 1.62.1 / Firefox 153, both fail; both pass on 1.60.0 / Firefox
150, which is how the upgrade surfaced them:
```
$ npx playwright test --project=firefox packages/lexical-playground/__tests__/e2e/Tables.spec.mjs -g "nested table shift-selection"
✘ Range-select from below nested table into it selects the entire table, but not the outer table
- Expected - 1
+ Received + 1
@@ -2,9 +2,9 @@ 1, 0, 0, 2, 1,
- 2,
+ 0,
$ npx playwright test --project=firefox packages/lexical-playground/__tests__/e2e/Selection.spec.mjs -g "Selecting table cell then dragging to outside of table should select entire table"
✘ Selecting table cell then dragging to outside of table should select entire table
- Expected - 0
+ Received + 3
Array [ 1, 1, +1, +0, +0, 0 ]
```
Tracing the selection through the shift-click shows the two engines agreeing
right up to the click, then Firefox moving the anchor:
```
chromium firefox 153
after typing paragraph#2 > text"after" off=5 paragraph#2 > text"after" off=5
after Shift down paragraph#2 > text"after" off=5 paragraph#2 > text"after" off=5
after shift-click paragraph#2 > text"after" off=5 paragraph#0 > text"before" off=0
```
### After
```
$ npx playwright test --project=firefox packages/lexical-playground/__tests__/e2e/Tables.spec.mjs -g "nested table shift-selection"
✓ Range-select from above nested table into it selects the entire table, but not the outer table (6.2s)
✓ Range-select from below nested table into it selects the entire table, but not the outer table (4.5s)
2 skipped
2 passed (13.8s)
$ npx playwright test --project=firefox packages/lexical-playground/__tests__/e2e/Selection.spec.mjs -g "Selecting table cell then dragging to outside of table should select entire table"
✓ Selecting table cell then dragging to outside of table should select entire table (5.4s)
1 passed (7.8s)
$ pnpm run ci-check
CI-CHECK EXIT=0
$ pnpm run test-unit
Test Files 294 passed (294)
Tests 5547 passed | 1 skipped (5548)
```
The source change is inside `IS_FIREFOX &&`, so no other engine's behaviour
moves. The full Firefox e2e sweep is still running at the time of this commit.
WebKit was not exercised: its playwright build does not launch in this
container.
…nested table no longer selects the whole cell
## Description
Shift-clicking from inside a nested table out to text beside it selected the
entire surrounding cell on Firefox, instead of extending the range from the
nested table's edge to the click.
`$handleTableClick`'s Firefox path builds a TableSelection from the previous
anchor's cell to the clicked cell. Only the nearest cell's observer is handed
the pointerdown, so this arrives with `tableNode` set to the *outer* table, and
`$findParentTableCellNodeInTable` walks past the nested table the anchor is in
to the cell of `tableNode` that contains it — which is also the cell that was
clicked. Anchor cell and focus cell are then the same cell, and a TableSelection
across one cell covers it end to end. That is what "erroneously selects the
entire outer cell" was.
A TableSelection only means something when the two ends are in different cells,
so it is now made only then. With both ends in one cell there is nothing
spanning cells, and what belongs there is an ordinary range inside it, which the
engine resolves on its own.
That fixes the downward case. The upward one — shift-clicking to text *above* a
nested table — is still wrong on Firefox and keeps its `test.fixme`, with the
reason it carries now recorded: Firefox resolves that click as whole cells of
the nested table, so what Lexical imports is a TableSelection rather than a
range, and `$fixRangeSelectionForSelectedTable` — which already computes the
right answer for a range that starts inside a table and ends outside it, and is
what makes Chromium correct — never gets to run. Reconstructing both ends at
pointerdown from the event coordinates was tried and made the downward case
fail, so it is not in this change.
## Test plan
### Before
```
$ npx playwright test --project=firefox packages/lexical-playground/__tests__/e2e/Tables.spec.mjs -g "nested table shift-selection"
✓ Range-select from above nested table into it ... (6.1s)
✓ Range-select from below nested table into it ... (4.8s)
- Range-select from inside nested table to text above it ... [fixme, firefox]
- Range-select from inside nested table to text below it ... [fixme, firefox]
2 skipped
2 passed
```
Tracing the shift-click shows Firefox producing a TableSelection whose anchor
cell and focus cell are the same outer cell, where Chromium produces a range
anchored at the nested table's edge:
```
firefox TableSelection A=...>tablecell#1@0(element) F=...>tablecell#1@0(element)
chromium RangeSelection A=...>table#1>tablerow#1>tablecell#1@1(element)
F=...>paragraph#0>text#0"before"@3(text)
```
### After
```
$ npx playwright test --project=firefox packages/lexical-playground/__tests__/e2e/Tables.spec.mjs -g "nested table shift-selection"
✓ Range-select from above nested table into it ... (6.1s)
✓ Range-select from below nested table into it ... (4.8s)
- Range-select from inside nested table to text above it ... [fixme, firefox]
✓ Range-select from inside nested table to text below it ... (5.0s)
1 skipped
3 passed (18.8s)
$ npx playwright test --project=chromium packages/lexical-playground/__tests__/e2e/Tables.spec.mjs -g "nested table shift-selection"
4 passed (18.4s)
$ pnpm run ci-check
CI-CHECK EXIT=0
$ pnpm run test-unit
Test Files 294 passed (294)
Tests 5547 passed | 1 skipped (5548)
```
The change is inside `IS_FIREFOX &&`, so no other engine's behaviour moves. The
full Firefox e2e sweep is still running at the time of this commit. WebKit was
not exercised: its playwright build does not launch in this container.
…054-review-t5gagd
Two conflicts, both where main reached the same tests from the other side.
`Selection.spec.mjs`: main fixed the single-jump `page.mouse.move` out of a
table with `{steps: 10}` as well. The code is identical, only the comment
differed, so main's is kept.
`Tables.spec.mjs`: main added a `test.fixme` on "Range-select from below nested
table into it" for the behaviour this branch fixes in
`$handleTableClick` — the anchor-preserving branch of the Firefox shift-click
workaround was unreachable. The fixme is dropped, since the test passes here.
Its sibling "from above nested table into it" takes the same code path and is
already green on the windows firefox job, so this is not a linux-only result.
The two remaining fixmes keep their skips but say what is actually wrong now
rather than only the symptom, including that "to text below it" fails on
windows firefox specifically.
…t-click and re-narrow the Firefox path
## Description
Two problems in the Firefox shift-click handling added earlier on this branch,
plus a comment that overclaimed.
`$handleTableClick` skips making a TableSelection when both ends of the
shift-click are in one cell, since a table selection over a single cell is what
"erroneously selects the entire outer cell" was. But that made the case a
complete no-op, and it sits inside the outer `if`, so the `else` that records
the anchor was not reached either. `createPointerHandlers` adopts its
`startingCell` only when `anchorCell` is null, so a cell left over from an
earlier click survived and a drag begun on this pointerdown anchored there. The
observer's anchor is now recorded for the clicked cell — `$setAnchorCellForSelection`
is bookkeeping and never sets the selection, so this changes nothing else.
Dropping `$isSelectionInTable(prevSelection, tableNode)` also widened the path
further than intended. It was dropped so a shift-click into a table nested in a
cell would reach the branch that preserves the anchor, which needs an anchor
outside `tableNode`. But it also let in an anchor in an unrelated table, where
the same branch focuses `tableNode`'s edge rather than the clicked cell and now
stops the event so Firefox cannot resolve it either —
`$fixRangeSelectionForSelectedTable` matches none of `shouldMoveFocus`,
`shouldMoveAnchor` or `isSameTable` for a cross-table pair, so nothing corrects
it. The guard is back, or-ed with exactly the nested case: the cell the previous
anchor sits in is a parent of `tableNode`.
`TableNode.exportDOM`'s comment said `$convertTableElement` reads the moved
attributes back. It reads the direction (`$setDirectionFromDOM`) and nothing
restores a table's indent, so the comment and the test's now say which of the
two round-trips. The indent still belongs in the export: it is what
`ElementNode.exportDOM` emits for every other element and what renders the
indent outside of Lexical.
## Test plan
### Before
Reported by `/code-review` against this branch; both are state/edge problems
rather than assertions the suite makes, so they are reasoned from the code:
`createPointerHandlers` at line 301 assigns only `if (startingCell !== null &&
tableObserver.anchorCell === null)`, and `$fixRangeSelectionForSelectedTable`
has no branch for an anchor and focus in two unrelated tables.
### After
```
$ npx playwright test --project=firefox packages/lexical-playground/__tests__/e2e/Tables.spec.mjs -g "nested table shift-selection"
✓ Range-select from above nested table into it ... (6.5s)
✓ Range-select from below nested table into it ... (4.6s)
2 skipped
2 passed (13.9s)
$ npx playwright test --project=chromium packages/lexical-playground/__tests__/e2e/Tables.spec.mjs -g "nested table shift-selection"
4 passed (19.2s)
$ npx vitest --project unit --no-watch packages/lexical-table/src/__tests__/unit
Test Files 19 passed (19)
Tests 179 passed (179)
$ pnpm run ci-check
CI-CHECK EXIT=0
$ pnpm run test-unit
Test Files 297 passed (297)
Tests 5564 passed | 1 skipped (5565)
```
The full Firefox e2e sweep on the parent commit was 804 passed, 62 skipped, and
is re-running for this one. WebKit was not exercised: its playwright build does
not launch in this container.
Description
Eleven small table bugs, consolidated into one branch per the review feedback
on #9027 and #9035. They fall into three groups.
1. Grid geometry
Code that uses a row's child index where the table grid column index is
required, or that ignores a span. These agree only while every cell has
colSpan === 1/rowSpan === 1, so they are invisible until a table has mergedcells.
$insertTableColumnAtNode(packages/lexical-table/src/LexicalTableUtils.ts)walked leftwards from the insertion column looking for the cell to insert
after. When every grid position at or before the insertion column is covered
by a
rowSpanfrom an earlier row, the walk fell off the left edge andappended the new cell to the end of the row, so the inserted column did not
line up. Replaced with the same left-to-right map scan
$unmergeCellNodeuses: track the last row-map entry with
startRow === iat or before theinsertion column,
insertAfterit, or$insertFirstwhen the row ownsnothing to the left. This also removes the labeled
continue. ([lexical-table] Bug Fix: insert column after the correct cell in rows covered by a rowSpan #8836)toggleTableColumnIsHeader(
packages/lexical-playground/src/plugins/TableActionMenuPlugin/index.tsx)fed
$setTableColumnIsHeader, which indexesgridMap[row][columnIndex], theresult of
$getTableColumnIndexFromTableCellNode— the cell's index among itsrow's children. With an earlier spanning cell in the row, "Toggle column
header" applied to a column left of the one clicked. It now reads
cellMap.startColumnfrom$computeTableMap. ([lexical-playground] Bug Fix: toggle the column header of the clicked cell's grid column #9006)2. Cell and table state
Transforms that rebuild a cell or its paragraph and drop what it carried, plus
the
dirattribute being written onto an element that the export throws away.$insertTableIntoGrid(LexicalTableUtils.ts) copies the template cell'sbackgroundColoronto the destination cell but notverticalAlign, whichwas added to
TableCellNodeafter that loop ([lexical-table] Feature: TableCellNode add verticalAlign attribute #7077). Pasting a table withvertically aligned cells over an existing table dropped the alignment. ([lexical-table] Bug Fix: keep the pasted cell's verticalAlign when a table is inserted into a grid #9015)
$tableTransform(LexicalTablePluginHelpers.ts) pads short rows out to thetable width with
$createTableCellNode()and no header state, so a shortheader row was repaired into a mix of
<th>and<td>. The padding cells nowinherit the
TableCellHeaderStates.ROWbit from the row's last cell — thesame reference
$insertTableColumnAtNodeuses when it appends a column. ([lexical-table] Bug Fix: padding cells inherit the header row state #9023)$unmergeCellNode(LexicalTableUtils.ts) recomputes the header state of thecells it splits off, correctly, but gives them nothing else, so a filled
merged cell unmerged into one filled cell and a run of blank ones. The split
cells now keep the original's
backgroundColorandverticalAlign, which isthe cell's own presentation and not a description of its row or column. ([lexical-table] Bug Fix: unmerged cells keep the merged cell's backgroundColor and verticalAlign #9025)
TableNode.exportDOM(LexicalTableNode.ts) narrows the export toelement.querySelector('table'). When scrollable tables are activecreateDOMreturns the scroll wrapper<div>, which is whereElementNode.exportDOMwritesdir— so the wrapper, and the direction withit, was thrown away. The direction is now re-applied to the
<table>, whichis where
$convertTableElementreads it back. ([lexical-table] Bug Fix: export the table's dir when scrollable tables are active #9029)TableObserver.$clearText(LexicalTableObserver.ts) emptied each selectedcell by constructing a fresh
ParagraphNode, so Backspace over a multi-cellselection also reset the format, style, direction and indent of those cells.
It now
$copyNodes the cell's existing paragraph, which carries the elementstate and returns a childless copy. ([lexical-table] Bug Fix: clearing table cells keeps each cell's paragraph state #9041)
3. Selection and caret at the table boundary
KEY_ARROW_LEFT_COMMAND/KEY_ARROW_RIGHT_COMMANDhandlers inregisterRichText(packages/lexical-rich-text/src/index.ts) had noequivalent of the
$isSelectionAtEndOfRoot/$isSelectionAtStartOfRootguardsthe up/down handlers already use. With a table as the last node of the
document the key fell through to the native caret, which walks around the
block cursor element, so the caret cycled: last cell → block cursor → root
offset before the table → back into the last cell. A new
$isBlockCursorAtRootEdgeconsumes the key when the collapsed element pointsits at the root edge beside a child that needs a block cursor.
Non-collapsed selections and block cursors that still have a sibling to move
into are untouched. ([lexical-rich-text][lexical-table] Bug Fix: caret no longer cycles around a trailing table #8949, fixes Bug: Odd selection behavior with table as last element in document #7999)
$handleArrowKey(LexicalTableSelectionHelpers.ts) armed the Firefoxscrollable-table workaround (
setShouldCheckSelectionForTable) on everyArrowDown. From the block cursor below a trailing table ArrowDown moves
nothing, so the flag survived to be consumed by the next selection change —
an ArrowUp back into the table — which snapped the caret to the first cell.
A new
$isSelectionBeforeTablearms it only when the focus is before thetable in document order, the only side ArrowDown can enter from.
([lexical-table] Bug Fix: ArrowUp from the block cursor below a table returns to the last row #8963, fixes Bug: BlockCursorElement inconsistent/unresponsive behavior #6822)
$deleteTableRowAtSelection(LexicalTableUtils.ts) removes the tableoutright when the selection covers every row, but never moved the selection
first, leaving a
TableSelectionanchored to detached nodes. Added thegrid.selectPrevious()that$deleteTableColumnAtSelectionandTableObserver.$clearTextalready do in their identical branches. ([lexical-table] Bug Fix: move the selection out of the table before deleting its last rows #9037)$adjustFocusInDirection(LexicalTableSelectionHelpers.ts) calledgetCornerOrThrowon the rect from$computeTableCellRectBoundary, whichgrows the rect until it contains every merged cell straddling an edge — so
the anchor is not guaranteed to be at a corner, and Shift+Arrow killed the
editor update with an invariant.
getCornerOrThrowis replaced bygetAnchorCorner, which falls back the same way$extractRectCorners24lines below already does: to the corner opposite the focus, then to the
top-left. ([lexical-table] Bug Fix: Shift+Arrow no longer throws when the anchor is off the rect corner #9045)
Test plan
Unit tests cover ten of the eleven fixes, two browser tests cover the
caret/arrow-key behaviour at the table boundary, and #9006 is a Playwright spec
(
packages/lexical-playground/__tests__/regression/7266-column-header-merged-cells.spec.mjs).Before
Source fixes reverted, new tests kept:
The remaining new cases pass on both sides of the change — the unstyled-unmerge,
short-body-row, non-wrapped-export, delete-every-column and
still-owns-a-cell-to-the-left cases — which is what pins each asymmetry rather
than the fix itself.
After
Supersedes #8836, #8949, #8963, #9006, #9015, #9023, #9025, #9029, #9037,
#9041, #9045, consolidated per the review feedback on #9027 and #9035.
#9000 and #9011 were part of an earlier revision of this PR and have been
dropped, because each contradicted an existing e2e expectation rather than
extending it:
dirin theDOMImportExtensiontable rules. Google Sheetsemits
<table dir="ltr">unconditionally, soCopy + paste (Table - Google Sheets)inTablesHTMLCopyAndPaste.spec.mjswent fromdir="auto"to apinned
dir="ltr"on the table, and the rows below it stopped emittingdir="auto"at all. Honouring a pasteddiris a deliberate behaviour changefor third-party HTML and needs its own PR.
spans instead of its first.
Resize merged cells width (2)inTables.spec.mjspins the existing behaviour, and both variants widen themerged cell identically — they differ only in which unmerged column absorbs
the change, so this is a behaviour preference that needs a maintainer call.