Repository navigation
fix(muya): skip empty sibling containers in caret navigation (#4644 follow-up) - #4715
Conversation
marktext#4644) previousContentInContext / nextContentInContext returned null when the adjacent sibling was an empty container with no content descendant — e.g. a list item whose only paragraph was removed during editing, or an empty `* ` item parsed from markdown. That left ArrowUp/ArrowDown unable to cross the empty item, so the caret got stuck and could only be moved by clicking. Walk the previous/next siblings and skip empty containers, falling through to the parent only when no sibling holds content. Add regression tests covering ArrowUp and ArrowDown across an empty list item (they fail without the fix).
|
This PR fix the same issue as #4691 ? also solve the empty list item. |
|
Good question — they're complementary, not the same. #4691 fixes serialization ( This PR fixes caret navigation ( Different files, different layers, no overlap — and they reinforce each other: since #4691 keeps an empty list item as a valid, preserved state, navigation has to handle it. The navigation bug reproduces independently of serialization: muya.setContent('* A\n* \n* B') // childless middle item
// caret in "B" → ArrowUp no longer reaches "A"No shared files, so they don't conflict — happy to coordinate ordering if you'd prefer one to land first. |
|
How to produce this issue, in 0.20.0-beta.2? |
|
Confirmed on 0.20.0-beta.2. The original report's keystroke sequence no longer triggers it on beta.2 — that editing path was fixed by #4660. It still reproduces by loading the empty list item from Markdown, which #4660 doesn't touch:
The empty item parses to a |
So the root cause is markdown to state? #4691 (review) |
|
Yes — the childless So your call in #4691 is the right altitude: mirroring the blockquote handling for empty list items fixes #4679 and this on-load navigation symptom at the source. This PR is then the defense-in-depth guard you mentioned — childless containers can still arrive via OT ops / paste / programmatic |
|
I think this defensive fix can be retained to avoid generating empty list items and empty quote blocks due to other missed spots elsewhere. |
Follow-up to #4660, which closed #4644.
#4660 fixed the editing path that produced a childless list item (Enter on the empty first paragraph of a loose list item). But a childless list item can also come straight from Markdown, which #4660 doesn't touch — so the original symptom still reproduces:
With the caret in "B", ArrowUp no longer moves up to "A" (and ArrowDown from "A" can't reach "B"). The cause is exactly the one #4660's commit message names:
previousContentInContext/nextContentInContextreturnnullwhen the adjacent sibling is an empty container with no content descendant.Fix
Make the two navigation helpers walk the previous/next siblings and skip empty containers, falling through to the parent only when no sibling holds content. Symmetric for both directions, so navigation is robust regardless of how the empty container arises.
Tests
Adds ArrowUp/ArrowDown regression tests in
arrowNavigation.spec.ts(a list with an empty middle item viasetContent('* A\n* \n* B')); both fail without this change. Full muya suite (unit + conformance), typecheck, lint, circular-dep, and build all pass locally.Context: I left a heads-up on the issue first — #4644 (comment)