Repository navigation
fix(muya): keep blocks after a paragraph merged into a table cell out of the row (#5386) - #5422
Merged
Merged
Conversation
… 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]>
…5386) Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.deleteHandlermerges 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 tothis.parent, the block that holds the caret's text.In a table cell,
this.parentistable.cell, so:paragraphBlock.parent !== this.parent.parentcompared the paragraph's container withtable.row. That is never equal, so the move also ran when the paragraph was a plain sibling of the table;q, or the- csublist in the list variant) were inserted intotable.row. A row's state only holds cells, so the json1 operation failed inJSONState._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 ofthis.parent. For paragraphs, ATX/setext headings and thematic breaks it returnsthis.parent, so their behavior is unchanged. For a table cell it returns the whole table. As a result:| 1 | 2 |thenpthenq:pis merged (2p) and nothing moves, soqstays below the table;a, followed by itembwith sublist- c:bis merged into the cell and- clands after the table in itema.Type of change
Test plan
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 throwCannot use numerical key for object containerwithout the fix.editing/table-last-cell-delete-5386.spec.ts, Chromium, real clicks and key presses): the issue's steps (click end of2, Delete, typez, click end ofx, typew) give| xw | y |/| 1 | 2zp |thenq; the list variant gives2zbwith- cafter the table; no page errors. Both fail without the fix, with the markdown still at the original document.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 --noEmitandcheck-circularpass; ESLint reports no errors on the changed files.paragraph-menu-in-table-or-code-4944,cut-into-table-5400,table-cell-selection,cross-block-enter(11 passed).🤖 Generated with Claude Code