Skip to content

fix(muya): keep list item non-empty on Enter in empty first paragraph (#4644) - #4660

Merged
Jocs merged 1 commit into
developfrom
fix/4644-list-empty-item-arrow-nav
Jun 23, 2026
Merged

Jocs merged 1 commit into
developfrom
fix/4644-list-empty-item-arrow-nav

Conversation

@Jocs

@Jocs Jocs commented Jun 23, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #4644 — after a series of list edits, the Up arrow stops moving the caret up a line and the user has to click instead.

Root cause

ParagraphContent._enterInListItem handles pressing Enter on an empty paragraph that is not the only child of a loose list item by moving every paragraph from the caret's index to the end of the item into a new sibling list item:

const offset = listItem.offset(parent!)
listItem.forEachAt(offset, undefined, (node) => { /* move to new item */ })

When the caret sits on the first paragraph (offset === 0), this moves all paragraphs out and leaves the original list-item with children: []. A childless list item has no content descendant, so previousContentInContext/nextContentInContext return null when arrow navigation tries to step over it — Content.arrowHandler then preventDefaults the Up arrow but finds no previous block to land on, so the caret cannot move up.

The reported sequence (* ␣ A ⏎ B ↑ ⏎ ⌫ ↑ ⏎ ⏎ ⏎) walks the document into exactly this state.

Fix

When the empty paragraph is the first child, split from the next paragraph instead, keeping the empty first paragraph in the original item. This mirrors the established plain-paragraph "Enter at offset 0" behaviour and keeps every list item valid (≥1 content child).

Tests

  • Unit (enterListItemEmptyFirst.spec.ts) — pins the engine invariant: Enter on the empty first paragraph of a multi-paragraph list item never yields a childless list item, and splits into two non-empty items.
  • E2E (list-nav-4644.spec.ts) — drives the exact reported keystroke sequence in a real browser and asserts (1) no empty list item remains and (2) Up arrow still moves the caret to an earlier content block. Both tests were confirmed to fail on the unfixed source and pass with the fix.

🤖 Generated with Claude Code

…#4644)

Pressing Enter on the empty first paragraph of a loose list item (one that
holds multiple paragraphs) moved every paragraph from the caret's index into
a new sibling list item. When the caret was on the first paragraph (index 0),
this emptied the original list item, leaving a `list-item` with zero children.

A childless list item has no content descendant, so
`previousContentInContext`/`nextContentInContext` return null when arrow
navigation tries to cross it — Up arrow then stopped moving the caret up a
line, the symptom reported in #4644.

Split from the next paragraph when the caret is on the first one, mirroring
the plain-paragraph "Enter at offset 0" behaviour, so the original list item
keeps its empty first paragraph and stays valid.

Adds a unit test for the engine invariant and an e2e regression test driving
the exact reported keystroke sequence.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@Jocs
Jocs merged commit 3e71b36 into develop Jun 23, 2026
7 checks passed
@Jocs
Jocs deleted the fix/4644-list-empty-item-arrow-nav branch June 23, 2026 13:56
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.

[Bug] keyboard navigation issue with lists

1 participant