Skip to content

fix(muya): keep a nested sublist when forward-deleting an empty list item (#1845) - #4725

Merged
Jocs merged 1 commit into
developfrom
fix/1845-list-delete-orphan-sublist
Jun 26, 2026
Merged

Jocs merged 1 commit into
developfrom
fix/1845-list-delete-orphan-sublist

Conversation

@Jocs

@Jocs Jocs commented Jun 26, 2026

Copy link
Copy Markdown
Member

Fixes #1845

Problem

Pressing Delete (forward-delete) at the end of an empty list item, where the next item owns a nested sublist, produced a doubled bullet:

* C

* - D

instead of the expected

* C

  - D

Root cause

Format.deleteHandler merges the next paragraph's text into the current content and then removes the next paragraph. The removal walks up only through only-child ancestors. When the next item's paragraph has a following sibling (a nested sublist), the walk stops at the paragraph, so just the paragraph is removed — leaving the sublist as the item's sole child. On serialization a list item that begins directly with a sublist renders with a second bullet (* - D).

Reproduced against the real engine (boot Muya, empty the first item, route a Delete through deleteHandler, read back getMarkdown()/getState()).

Fix

When the merge crosses a list-item boundary, relocate the merged paragraph's trailing siblings (the sublist) into the target item right after the merged paragraph, before removing the source paragraph. The source item is then empty and is removed whole by the existing only-child walk-up. Flat same-container merges (plain paragraph + paragraph) are untouched.

Tests

Added two regression tests to deleteMerge.spec.ts driving the real handler: the output no longer contains a doubled bullet, and the merged text + sublist land in the surviving item. Full muya unit suite (1302), CommonMark/GFM conformance (1347), lint, typecheck, and circular-dep checks all pass.

…ge (#1845)

Forward-Delete at the end of an empty list item merged only the next
item's paragraph text and removed that paragraph. When the next item also
held a nested sublist as a sibling of its paragraph, the sublist was
stranded as the item's sole child and serialized with a doubled bullet
(`* - D`).

Relocate the merged paragraph's trailing siblings into the target item
before removing the now-empty source item, so the whole content travels
up with the text.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@Jocs
Jocs merged commit 4d65a4a into develop Jun 26, 2026
7 checks passed
@Jocs
Jocs deleted the fix/1845-list-delete-orphan-sublist branch June 26, 2026 05:10
Jocs added a commit that referenced this pull request Sep 16, 2026
… of the row (#5386) (#5422)

* fix(muya): keep blocks after a paragraph merged into a table cell out 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]>

* test(muya): e2e for forward Delete at the end of a table's last cell (#5386)

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Jocs added a commit that referenced this pull request Sep 16, 2026
…ge (#5423)

Delete at the end of a paragraph merges the next paragraph into it. #4725
(fixing #1845) made that merge move every block after the next paragraph
out of its container whenever the two paragraphs sat in different
containers, so a nested sublist travels up with its list item's text. The
check did not require the container to be a list item, so merging a
blockquote's first paragraph also moved the quote's remaining paragraphs
out of it and the quote disappeared.

Only move the trailing blocks when the next paragraph's container is a
list item or a task list item. List items and task list items still carry
their trailing blocks along; a blockquote keeps its later paragraphs.

Fixes #5423

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Jocs added a commit that referenced this pull request Sep 16, 2026
…ge (#5423) (#5424)

* fix(muya): keep the rest of a blockquote quoted on forward-Delete merge (#5423)

Delete at the end of a paragraph merges the next paragraph into it. #4725
(fixing #1845) made that merge move every block after the next paragraph
out of its container whenever the two paragraphs sat in different
containers, so a nested sublist travels up with its list item's text. The
check did not require the container to be a list item, so merging a
blockquote's first paragraph also moved the quote's remaining paragraphs
out of it and the quote disappeared.

Only move the trailing blocks when the next paragraph's container is a
list item or a task list item. List items and task list items still carry
their trailing blocks along; a blockquote keeps its later paragraphs.

Fixes #5423

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* test(muya): e2e for forward Delete before a blockquote (#5423)

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* docs(muya): trim the forward-Delete merge comments (#5423)

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

---------

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

Development

Successfully merging this pull request may close these issues.

Deleting an item creates double itemization bullets in front of the next item

1 participant