Repository navigation
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
lexical
@lexical/a11y
@lexical/clipboard
@lexical/code
@lexical/code-core
@lexical/code-prism
@lexical/code-shiki
@lexical/compiler
@lexical/devtools-core
@lexical/dragon
@lexical/eslint-plugin
@lexical/extension
@lexical/fast-check
@lexical/file
@lexical/hashtag
@lexical/headless
@lexical/history
@lexical/html
@lexical/internal
@lexical/link
@lexical/list
@lexical/mark
@lexical/markdown
@lexical/mdast
@lexical/offset
@lexical/overflow
@lexical/plain-text
@lexical/react
@lexical/rich-text
@lexical/selection
@lexical/table
@lexical/tailwind
@lexical/text
@lexical/utils
@lexical/y
@lexical/yjs
commit: |
There was a problem hiding this comment.
Thanks, this looks good. Routing DELETE_CHARACTER_COMMAND and DELETE_WORD_COMMAND through $deleteCellHandler makes word delete and Ctrl+H/Ctrl+D behave like Backspace and Delete, and the parent-point fallback fixes the adjacent-table case and the table-at-the-edge-of-a-cell case. I reproduced the new unit and browser tests failing against main's implementation and passing with this change. The two suggestions below are optional and non-blocking.
-
A table at the end of a container above is now deleted too (
packages/lexical-table/src/LexicalTableSelectionHelpers.ts:926). The fallback runs only when the sibling is aTableNode. Suppose the sibling is instead an element whosecanBeEmpty()returnsfalse, soElementNode.select()descends into its last child, and it ends with a table. ThenselectPrevious()still lands inside that table. Because rich text's Backspace now re-enters the table listeners throughDELETE_CHARACTER_COMMAND, that table widens around itself as well.Reproduced locally in Chromium with real keys. The document is
p, a shadow-root container withcanBeEmpty() === falseholdingkand a one-cell table, a tablec/d, thenqr. With the caret at the start ofqr, press Shift+ArrowUp, then Backspace.mainremoves onlyc/d; this branch also removes the container's table.Deciding by where the moved point lands, rather than by the sibling's type, fixed it in my local run for Backspace,
DELETE_CHARACTER_COMMANDandDELETE_WORD_COMMAND, and all 47 new cases still pass:const newSelection = tableNode[isBefore ? 'selectPrevious' : 'selectNext'](); const landedIn = $findTableNode(newSelection[tablePoint].getNode()); if (landedIn !== null && !landedIn.isParentOf(tableNode)) { const parent = tableNode.getParentOrThrow(); const index = tableNode.getIndexWithinParent() + (isBefore ? 0 : 1); newSelection[tablePoint].set(parent.getKey(), index, 'element'); } newSelection[outerPoint].set(key, offset, type);
A case for this layout in
CASESwould keep it covered. -
Optional test addition: the "into the earlier of two tables" case (
packages/lexical-table/src/__tests__/unit/DeleteRangeIntoTable.test.ts:188-199) runs only the forward commands. The changeset'sVerify:paragraph also promises Backspace for that range, so a Backspace case for the same selection (it passes on this branch locally) would pin that claim.
3d5214d to
4a8b676
Compare
There was a problem hiding this comment.
This looks good — thanks for the rework since the last round. Moving DELETE_CHARACTER_COMMAND and DELETE_WORD_COMMAND onto $deleteCellHandler, and checking where the widened end actually lands instead of the sibling's type, makes word delete and Ctrl+H on a range into a table behave like Backspace, and also fixes the adjacent-table and edge-table cases Backspace already got wrong.
What I checked:
- The new unit file fails 95 of its 176 cases against the
mainimplementation ofLexicalTableSelectionHelpers.tsand passes all 176 on this branch (reproduced locally), matching your test plan's Before and After output. - The real-key browser test passes in this PR's CI browser jobs for Chromium, Firefox and WebKit.
- The changeset is a
@lexical/tablepatch[fix]entry with aVerify:paragraph, which is what CONTRIBUTING.md and.changeset/README.mdask for a fix that changes editing behavior.
One optional, non-blocking suggestion:
- Optional: add a case for a shadow root the range only partly covers (
packages/lexical-table/src/__tests__/unit/DeleteRangeIntoTable.test.ts:404-414). The climb inLexicalTableSelectionHelpers.ts:933-944can move the end out of a shadow root other than a cell, but the only shadow-root case has the range cover the whole container. Something like$build: () => [$p('p'), $shadowBox($table([['x']]), $p('k')), $p('q')]withselect: ['k', 0, 'x', 0],backward: trueandexpected: 'p(p) box(p(k)) p(q)'would pin that the container and the rest of its content stay. It already behaves that way when I tried it locally; the case would keep it so if the core removal logic changes.
4a8b676 to
30cb92a
Compare
|
Added that case ( |
There was a problem hiding this comment.
This looks good to me. Sending DELETE_WORD_COMMAND and DELETE_CHARACTER_COMMAND through $deleteCellHandler fixes the word-delete and Ctrl+H case. Moving the end beside the table when selectPrevious/selectNext lands in another table fixes the adjacent-table case. I reproduced both locally: the new unit file fails 103 of 184 with LexicalTableSelectionHelpers.ts from main and passes on this branch. The browser test fails for word Backspace and word Delete on main in Chromium and passes here. With two adjacent tables, real keys now remove only the selected table, and typing afterwards lands in the paragraph beside it.
One optional, non-blocking suggestion:
- Optional: pin two more shapes this change fixes (
packages/lexical-table/src/__tests__/unit/DeleteRangeIntoTable.test.ts:404-421). The shadow-root cases only cover a table that starts the root. Two other shapes are fixed here too. A table ending a shadow root, with the range running forward from inside it (shadow(p(k) table(x)),k@1→x@0):mainleaves an emptied table in the root for Backspace, Delete and both text commands. A range from a cell's paragraph into the first of two tables in that cell (td(p(A) table(a) table(c)),A@1→a@0):main's Backspace also losesc. A case for each, for exampleinto a table ending a shadow root from inside itandinto the first of two tables in a cell, would keep them from regressing.
30cb92a to
bc37654
Compare
|
Added both ( |
There was a problem hiding this comment.
This looks good, and thanks for the thorough test matrix: I ran the new unit and browser tests locally, and they fail against the main implementation and pass on this branch. Two optional, non-blocking suggestions:
-
Consider: the end-repair climb passes through shadow roots (
packages/lexical-table/src/LexicalTableSelectionHelpers.ts, lines 934-944). The loop stops only at a table cell or a top-level node, so when a table starts an element that is a shadow root and cannot be empty (the playground'sPageContentNodeis one), a range from the end of that element's content back into the table now deletes the shadow root itself, plus a single-child wrapper such asPageNode. Core keeps an emptied shadow root (the!$isRootOrShadowRoot(this)guard inElementNode.splice,packages/lexical/src/nodes/LexicalElementNode.tsline 879), and the same range with a paragraph in place of the table leaves the container holding an empty paragraph. Reproduced locally withshadow(table(x), p(k))and the rangek@1 -> x@0: Backspace, both text commands and a cut all givep(p) p(q), whilemainleaves an emptied table, so this is not a regression from correct behavior. If keeping the container is the intent, stopping the climb at a shadow root that holds the other end, as the cell check right below it does for cells, would do it; either way, a case likeinto a table starting a shadow root from its endwould pin the intended result. -
Nit: refresh the Test plan's counts. The Before and After blocks show 184 tests, but
DeleteRangeIntoTable.test.tsnow runs 200 after the two cases added in the last push (into a table ending a shadow root from inside it,into the first of two tables in a cell); locally it is119 failed | 81 passed (200)against themainimplementation and200 passed (200)on this branch. AGENTS.md asks the Test plan to carry the real output of the command that was run.
The changeset follows CONTRIBUTING.md, including the Verify: paragraph a behavior fix needs.
bc37654 to
48e8ab8
Compare
|
Done. The climb now stops at any element holding the other end (the same results as a shadow-root-only check on every layout I tried), so a shadow root holding both ends stays, emptied. |
There was a problem hiding this comment.
Thanks, this looks good. Routing DELETE_CHARACTER_COMMAND and DELETE_WORD_COMMAND through $deleteCellHandler makes word delete and Ctrl+H/Ctrl+D remove the whole table the way Backspace already does, and the landedIn repair also fixes the adjacent-table and nested-table cases main got wrong. Reproduced locally: the new unit tests fail 135 of 216 against main's handler and all pass with this change, and the browser test's two word-delete cases fail on main and pass here. The changeset follows CONTRIBUTING.md (patch, [fix], a Verify: paragraph).
One optional, non-blocking suggestion:
- Nit: the climb does not stop at the element the other end sits on. In
packages/lexical-table/src/LexicalTableSelectionHelpers.ts:942,!parent.isParentOf(outerNode)is false when the outer point is an element point onparentitself, which selection normalization keeps when that element's edge child is a decorator. With a non-shadow element whosecanBeEmpty()is false,box(table(x), deco), and a range from(box, 2)back tox@0, Backspace and both text commands leavebox(), an element that cannot be empty with no children (mainleavesbox(table(p()))). Writing!parent.is(outerNode) && !parent.isParentOf(outerNode)makes the loop stop there, as its comment describes ("an element holding the other end"), and the box then goes with the table as ininto a table starting a box from its end; the 216 tests still pass with that change locally. A case for that shape inCASESwould pin whichever result you intend.
…side it is deleted by character or word ## Description A range with one end outside a table and the other inside it, which Shift+Arrow or a mouse drag from below the table into it leaves, is expanded to cover the whole table on Backspace and Delete. Deleting the same range by word (Option+Backspace on macOS, Ctrl+Backspace elsewhere) or with Ctrl+H / Ctrl+D on macOS dispatches `DELETE_WORD_COMMAND` or `DELETE_CHARACTER_COMMAND`, whose table handler did not expand it, so the editor removed part of the table and left an emptied fragment, or a cell spanning two rows in a one-row table. `DELETE_CHARACTER_COMMAND` and `DELETE_WORD_COMMAND` now go through the same table handler as Backspace and Delete. When `selectPrevious` / `selectNext` moves the end in the table out of it, the end can land inside another table: an adjacent one, or one at the edge of an element that cannot be empty, because `ElementNode.select()` descends into such an element's first or last child. That table's own handler then expanded the range around it too, either in the same key command or when Backspace or Delete re-dispatches `DELETE_CHARACTER_COMMAND`. In that case the end now goes beside the table instead. The end can also land back in this table when the table is the first or last child of an element that cannot be empty; then it goes beside the outermost element the table is at that edge of, stopping at a table cell or at an element that holds the other end, so an element the range empties from outside is removed with the table instead of being left empty, and a cell keeps the rest of its content. A shadow root that holds both ends of the range stays even when the range empties it, as the core removal keeps it when the range holds no table. When it stops at a cell whose table does not hold the other end, the end stays where it landed: that table expands around itself too, and a cut, which only runs the first table's handler (meta#9281), behaves as it did before. This also fixes cases Backspace and Delete already got wrong: a range from the paragraph above into the first of two adjacent tables, or into a table followed by such an element that starts with a table, removed the other table too, and a range into a table that is the first or last child of a cell, or that starts or ends another element that cannot be empty, left part of the table behind. `DELETE_LINE_COMMAND` keeps its existing behavior. ## Test plan ### Before `pnpm vitest run --project unit packages/lexical-table/src/__tests__/unit/DeleteRangeIntoTable.test.ts`: `Tests 138 failed | 81 passed (219)` `VITEST_BROWSER=chromium pnpm vitest run --project browser packages/lexical-table/src/__tests__/browser/DeleteRangeIntoTableKeys.test.ts`: `Tests 2 failed | 1 passed (3)` (word Backspace / word Delete leave `paragraph:p, table:, paragraph:b` instead of `paragraph:pb`) ### After The two files above: `Tests 219 passed (219)` and `Tests 3 passed (3)`. `pnpm run test-unit`: `Tests 41350 passed | 423 expected fail | 174 skipped`. `pnpm run test-e2e-chromium` / `-firefox` / `-webkit`: 661 / 627 / 641 passed.
48e8ab8 to
531e7c0
Compare
|
Done: the climb now also stops at the element the other end sits on, with a case for a box ending in a decorator. |
There was a problem hiding this comment.
This looks good to me. Thanks for the wide set of documents and for pasting the real Before/After output.
What I checked:
DELETE_WORD_COMMANDandDELETE_CHARACTER_COMMANDnow go through$deleteCellHandler, while aTableSelectionis still cleared withtruereturned andDELETE_LINE_COMMANDkeeps the old handler (packages/lexical-table/src/LexicalTableSelectionHelpers.ts, lines 876-1003).- The climb at lines 937-949 stops at any ancestor that is or holds the other end, so the element-point case from the inline thread (
box(table, decorator)with the range starting on the box) now keeps working, and the new decorator cases pin it. - Reproduced locally: the new unit file fails 138 of 219 cases with the
mainimplementation and passes on this branch, and the browser test's two word-delete cases fail onmain(paragraph:p,table:,paragraph:b) and pass here. In CI at this head the browser test passes in Chromium, Firefox and WebKit. - Also checked locally: one undo after the word delete restores the paragraph, the table and
ab, and a range into a table that starts or ends the document removes the whole table too.
The changeset follows .changeset/README.md ([fix] summary plus a Verify: paragraph). No changes requested.
Description
A range with one end outside a table and the other inside it is what Shift+ArrowUp from the paragraph below a table leaves, and so does a mouse drag from there up into the table (the table's selection handling moves the end to the start of the first cell). Backspace and Delete on that range remove the whole table, because
$deleteCellHandlermoves the end in the table to the table's outer edge first (#6650). Deleting the same range by word (Option+Backspace on macOS, Ctrl+Backspace elsewhere) or with Ctrl+H / Ctrl+D on macOS dispatchesDELETE_WORD_COMMANDorDELETE_CHARACTER_COMMANDinstead, and the table's handler for those only handled aTableSelection. The editor then removed part of the table: in Chromium, withp, a table ofc/dandab, Option+Backspace leftp, a table with one empty cell, andb. With a cell that spans two rows, it left that cell in a one-row table.DELETE_CHARACTER_COMMANDandDELETE_WORD_COMMANDnow go through$deleteCellHandlertoo. On its own that made Backspace worse.selectPrevious/selectNextcan put the moved end inside another table: an adjacent one, or one at the edge of an element that cannot be empty, becauseElementNode.select()descends into such an element's first or last child. That table's handler then expanded the range around itself as well, in the same key command or when Backspace or Delete re-dispatchesDELETE_CHARACTER_COMMAND. So when the end lands in a table that is not an ancestor of this one, it now goes beside this table, or beside the outermost element this table is at that edge of, stopping at a table cell or at an element that holds the other end. An element the range empties from outside then goes with the table instead of being left empty, and a cell keeps the rest of its content. A shadow root that holds both ends of the range stays even when the range empties it, as the core removal keeps it when the range holds no table. When the climb stops at a cell whose table does not hold the other end, the end stays where it landed, since that table expands around itself too and a cut only runs the first table's handler (#9281).That also fixes cases Backspace and Delete already got wrong on
main: a range from the paragraph above into the first of two adjacent tables, or into a table followed by such an element that starts with a table, removed the other table too, and a range into a table that is the first or last child of a cell, or that starts or ends another element that cannot be empty, left part of the table behind.DELETE_LINE_COMMANDkeeps its own handler and does not expand the range.Two things this does not touch. Cutting such a range with two tables in the document still goes through whichever table registered first (#9281). And #9285 moves the same expansion block into a
$selectAroundTablehelper, so whichever of the two lands second needs a small rebase.Changeset
.changeset/table-delete-range-into-table.md:@lexical/tablepatch,[fix], with aVerify:paragraph for the word delete / Ctrl+H case, the adjacent tables, the table inside a cell or another element that cannot be empty, and line deletion being unchanged.Test plan
The unit test runs every document with the selection in both directions and with Backspace, Delete and the two text commands, because each direction goes through a different part of the new branch. The documents cover adjacent tables, tables at the edge of cells and of elements that cannot be empty (nested, as a shadow root like the playground's page content, and in a slot value), and a cut. The browser test uses real Shift+ArrowUp and keys, and first checks that the selection really ends inside the table.
Before
pnpm vitest run --project unit packages/lexical-table/src/__tests__/unit/DeleteRangeIntoTable.test.tswithLexicalTableSelectionHelpers.tsfrommain:Tests 138 failed | 81 passed (219)
VITEST_BROWSER=chromium pnpm vitest run --project browser packages/lexical-table/src/__tests__/browser/DeleteRangeIntoTableKeys.test.tswith the same file frommain:After
The browser test also passes in Firefox and WebKit. In the playground (Chromium, Firefox and WebKit), Shift+ArrowUp or a mouse drag from below into the table, then Backspace, word Backspace or Ctrl+H, removes the whole table. With nested tables on, a range from the paragraph above into a table whose last cell ends with a table gives the same result as
mainfor Backspace and for a cut (Cmd+X) in all three.On a Galaxy S25 (Chrome 158), the Samsung Keyboard's delete key sends a Backspace keydown, so the range from below already removed the whole table before this change, and still does. With two adjacent tables and a range from the paragraph above into the first one, the same key removed both tables before and removes only the first one now. With HeliBoard, which sends only
beforeinput, the range had shrunk back into the paragraph before the delete, and both builds deleted one character. On an iPhone 12 (iOS 26.5, Safari), a range dragged with the selection handles from the first cell to the end of the paragraph below, deleted with the keyboard's delete key, removes the whole table before and after. With two adjacent tables, a range dragged from the paragraph above into the first one removed both tables before and removes only the first one now, as on the Galaxy.