Skip to content

fix(editor): align list item continuation lines with the item text - #800

Merged
murongg merged 3 commits into
markrahq:v2from
leemour:fix/list-continuation-indent
Nov 25, 2026
Merged

murongg merged 3 commits into
markrahq:v2from
leemour:fix/list-continuation-indent

Conversation

@leemour

@leemour leemour commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes list items whose text spans several source lines. Only the first line of such an item was decorated as a list line. The following lines started at the paper edge and showed their source indentation as a leading space:

- `pnpm test` runs vitest. `@wirecat/cli-base/testing/setup` gives each test file its own temporary home folder, a
  keyring that throws and no network, and points this CLI's config, state, cache and the shared store into that
  folder.
Before After
before after

Source line breaks still render as line breaks, as they do in paragraphs. Only the alignment changes.

Changes

  • packages/editor/src/codemirror/preview.ts: for each ListItem, every line of its direct Paragraph children after the item's first line gets a cm-markra-list-continuation line decoration with the item's data-list-depth and data-markra-list-source. This covers indented continuation lines, lazy continuation lines and later paragraphs of a loose item. While the caret isn't on the line, the leading indentation is hidden with pushHiddenRange, as the list marker's indentation is. Nested lists, fenced code and other children keep their own renderers. Lines are picked from the syntax tree, not by matching text.
  • packages/app/src/styles.css: the new class joins the existing depth-offset and hidden-source padding rules, so continuation text starts where the item text starts at every depth. It doesn't get the ::before marker or the sibling spacing rules of cm-markra-list-item.
  • packages/editor/src/codemirror/live-markdown.test.ts: tests for alignment at depth 0 and 1, ordered and lazy lines, nested lists and code blocks left alone, the same decorations after recreation, the indentation shown while the caret is on the line, and the document left unchanged.

Behavior

Caret Continuation line
Elsewhere Indented like the item text, source indentation hidden
On the line Source indentation shown, same as the first line's marker

Because the indentation is shown while the caret is on the line, Backspace at the start of the text deletes one visible space. It never deletes hidden text. Desktop and web behave the same.

Verification

  • pnpm --filter @markra/editor test: 688 passed, 1 failed. code-block.test.ts > opens, zooms, pans, and resets an enlarged Mermaid preview timed out at 5000 ms during the full run. Run on its own, it passes both on this branch and on v2 without the change.
  • pnpm --filter @markra/editor build and typecheck:test passed
  • pnpm --filter @markra/app test passed, 141 files and 1666 tests
  • pnpm --filter @markra/app typecheck:test and build passed
  • Runtime: apps/web in Chrome, with the before and after screenshots above. Each continuation line's computed padding-inline-start matches the item line (22.4px at depth 0). I'll also check it in a Linux desktop build.

Risks

  • I haven't checked continuation lines inside block quotes or callouts by hand.

I worked on this together with Claude Code.

🤖 Generated with Claude Code

A list item whose paragraph spans several source lines rendered only its
first line as a list line. The other lines had no list decoration, so they
started at the paper edge and showed their source indentation:

    - First line
      wrapped line   <- rendered at the left edge, with a leading space

Decorate every line of an item's own paragraphs after the first with
cm-markra-list-continuation. It carries the item's depth and source
visibility, gets the same inline padding as the item text, and hides the
leading indentation while the caret is not on the line, like the list
marker. Nested lists, code blocks and other children keep their own
renderers. Source line breaks still render as line breaks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 24, 2026

Copy link
Copy Markdown

@leemour is attempting to deploy a commit to the murongg's projects Team on Vercel.

A member of the Team first needs to authorize it.

@murongg murongg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please bound continuation decorations to visible lines before merging. The live Markdown suite passed all 118 tests. Chromium also confirmed alignment for ordinary list items, the out-of-viewport decoration count, and the task-list alignment gap below.

state.doc.lineAt(paragraph.from).number,
firstLineNumber + 1,
);
const endLine = state.doc.lineAt(paragraph.to).number;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Limit list continuation decorations to the visible ranges. The syntax-tree iteration is viewport-scoped, but this inner loop walks through the entire paragraph as soon as the list item intersects the viewport. A synthetic 12,000-line item created 12,000 continuation decorations with only 44 continuation lines in the visible range. Please intersect the paragraph with each visible range before decorating and test a long item as well as disjoint visible ranges around a fold.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6da66fc. The loop now intersects each paragraph with every visible range before walking its lines, so a long item only gets decorations for what is actually drawn. Added a test with a 40-line item and two disjoint visible ranges

firstLineNumber: number,
) => {
const depth = String(markraListDepth(item));
for (const paragraph of item.getChildren("Paragraph")) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Align continuation text in task items. With - [ ] Task first followed by an indented task next, the first paragraph is represented by a Task node, so this loop skips its continuation. A later plain paragraph gets the regular list indent but still starts to the left of the text after the checkbox. Please cover task continuations and align them with the item text, including the checkbox space.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, the first paragraph is a Task node so the loop never saw it. Fixed in 6da66fc - Task children are walked too, and task continuations get the checkbox width on top of the list indent. The test covers both the first paragraph and a later one

…k text

Review follow-up for the list continuation decorations.

The ListItem node is decorated once, but the continuation loop walked the
whole paragraph as soon as the item touched the viewport. A 12,000-line
item produced 12,000 line decorations for ~40 visible lines. Intersect each
paragraph with every visible range before walking its lines, so disjoint
ranges around a fold are covered and nothing outside them is decorated.

A task item's first paragraph is a Task node, not a Paragraph, so its
continuation lines were skipped. Later paragraphs got the plain list
indent and started left of the text after the checkbox. Walk Task children
too, mark task continuations with data-list-kind="task" when checkboxes are
rendered, and pad them by the checkbox width plus its end margin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@murongg
murongg merged commit f71ca31 into markrahq:v2 Nov 25, 2026
22 of 23 checks passed
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.

2 participants