Skip to content

fix(muya): keep blocks after a paragraph merged into a table cell out of the row (#5386) - #5422

Merged
Jocs merged 2 commits into
developfrom
fix/5386-table-last-cell-delete
Sep 16, 2026
Merged

Jocs merged 2 commits into
developfrom
fix/5386-table-last-cell-delete

Conversation

@Jocs

@Jocs Jocs commented Sep 16, 2026

Copy link
Copy Markdown
Member

Fixes #5386

Summary

Forward Delete at the end of a table's last cell, with at least two blocks after the table, threw Cannot use numerical key for object container. Every later keystroke threw again, and none of those edits reached the markdown, so Save wrote the original file. The next paragraph is now merged into the cell, and the blocks after it stay outside the table.

Cause

Format.deleteHandler merges the next paragraph into the current block. Since #4725 (#1845), when that paragraph is in another container it first moves the paragraph's following siblings next to this.parent, the block that holds the caret's text.

In a table cell, this.parent is table.cell, so:

  • the check paragraphBlock.parent !== this.parent.parent compared the paragraph's container with table.row. That is never equal, so the move also ran when the paragraph was a plain sibling of the table;
  • the following blocks (q, or the - c sublist in the list variant) were inserted into table.row. A row's state only holds cells, so the json1 operation failed in JSONState._flushOperationCache. The failed operation stayed queued, and every later flush threw with it.

With only one block after the table there was nothing to move, which is why that case worked.

Fix

Use this.getAnchor() instead of this.parent. For paragraphs, ATX/setext headings and thematic breaks it returns this.parent, so their behavior is unchanged. For a table cell it returns the whole table. As a result:

  • | 1 | 2 | then p then q: p is merged (2p) and nothing moves, so q stays below the table;
  • a table in list item a, followed by item b with sublist - c: b is merged into the cell and - c lands after the table in item a.

Type of change

  • Bug fix (non-breaking, fixes an issue)
  • New feature (non-breaking, adds functionality)
  • Breaking change (causes existing functionality to change)
  • Documentation update

Test plan

  • New tests added
    • Unit (tableCell/__tests__/deleteHandler.spec.ts, real engine): the issue's document, a later header-cell edit reaching the markdown, and the list variant. All three throw Cannot use numerical key for object container without the fix.
    • E2E (editing/table-last-cell-delete-5386.spec.ts, Chromium, real clicks and key presses): the issue's steps (click end of 2, Delete, type z, click end of x, type w) give | xw | y | / | 1 | 2zp | then q; the list variant gives 2zb with - c after the table; no page errors. Both fail without the fix, with the markdown still at the original document.
    • Also checked in the unit probe: a table inside a list item followed by two paragraphs in the same item, and a blockquote with two paragraphs after the table. Both threw before and serialize correctly now.
  • packages/muya: all unit tests pass (1804), deleteMerge.spec.ts (Deleting an item creates double itemization bullets in front of the next item #1845) included; tsc --noEmit and check-circular pass; ESLint reports no errors on the changed files.
  • Muya e2e in Chromium: the new spec plus paragraph-menu-in-table-or-code-4944, cut-into-table-5400, table-cell-selection, cross-block-enter (11 passed).

🤖 Generated with Claude Code

Jocs and others added 2 commits September 16, 2026 20:33
… of the row (#5386)

Forward Delete at the end of a table's last cell merges the next paragraph
into the cell. Since #4725 (#1845), when that paragraph sits in another
container, `Format.deleteHandler` moves the blocks that follow it next to
`this.parent`. For a cell that parent is `table.cell`, so the blocks were
inserted into `table.row`. It also took the branch when the paragraph was a
plain sibling of the table, because a cell's parent never shares the
paragraph's container. The json flush then threw "Cannot use numerical key
for object container", the failed operation stayed queued, and every later
edit threw too and never reached the saved markdown.

Use `getAnchor()` instead: the parent block for paragraphs and headings,
as before, and the whole table for a cell. A paragraph after the table is
merged without moving anything, and a merged list item's sublist lands after
the table.

Fixes #5386

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant