Skip to content

fix(list): keep nested children under the new item when Enter splits a list item - #506

Merged
mtskf merged 7 commits into
mainfrom
fix/list-enter-renumber-keeps-children
Nov 20, 2026
Merged

mtskf merged 7 commits into
mainfrom
fix/list-enter-renumber-keeps-children

Conversation

@mtskf

@mtskf mtskf commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Summary

Enter inside a list item now keeps the item's nested content under the new item when the split moves it under a marker with a different content column (e.g. 9. → 10., 99. → 100., or a source item with extra spaces after its marker). Before, a child sitting exactly at the old content column fell out of the list and became a top-level list.

Changes

  • list-transform.ts: extract the own-line column correction into shiftLine / shiftOwnLines, now the single implementation shared by renumberRun, the Tab/Shift-Tab planners (materialiseLineDeltas) and Enter.
  • shiftLine inserts spaces after the line's existing leading whitespace instead of at line.from: a space prepended before a tab is absorbed by the tab stop and moves nothing (the same latent bug existed in renumberRun). Space-only indentation produces identical bytes.
  • list-continuation-keymap.ts: on a split, resolve the item from the EOF tree for every list kind and shift its own lines (lazy lines excluded) by newContentCol - oldContentCol, in the same single transaction as the insert and the renumber.

Related

  • TODO: REV-20261119-02 (list Enter digit carry keeps children inside the parent item)

Test Plan

  • New cases in test/webview/list/cm-list-continuation-keymap.test.ts check the parse tree (the child's owning item is the new marker) and the bytes, and that one undo restores the original, for: 9→10, 99→100, tab-indented item and child, tab after the marker, extra spaces after an ordered / bullet marker, paragraph continuation, lazy line untouched, and a widened sibling renumber composed with the split.
  • Non-vacuity: moving the insertion point back to line.from turns the tab case red.
  • pnpm compile, Biome, test/webview/list + test/markdown (711 tests) green.
  • Full pnpm vitest run locally: 3 shell.test.ts "oversized content" tests fail on this machine, and they fail the same way on clean HEAD without this change. Two other timing-sensitive tests (cm-blockquote-collapse-nonlocal, cm-html-to-markdown linear-time) fail only under full-suite load and pass alone.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XMxzpbEvcdCeRd6i7DTsvt

…a list item

Enter moves the item's tail and its own lines under a freshly inserted
marker, but never shifted those lines to the new item's content column.
When the marker widens (9. -> 10.) a child sitting exactly at the old
content column fell out of the list.

Reuse the existing own-line classification and column correction for the
split: the shift is extracted into shiftOwnLines/shiftLine, shared by
renumberRun, the indent planners and Enter. Spaces now land after the
existing leading whitespace, because a space prepended before a tab is
absorbed by the tab stop and moves nothing.
…e width

Review found four column bugs in the split / renumber shift, all from
approximating columns by byte widths:

- a negative shift removed a whole tab straddling the target column, so
  a tab-indented child fell out of the list;
- a positive shift inserted after the whole leading whitespace, putting a
  space inside a fenced code line's own tab indentation;
- the split ignored whitespace at the start of the moved tail (`ab| cd`),
  which widens the new item's marker padding;
- renumber used the marker byte-width delta even when a tab after the
  marker absorbs the widening (`9.\t` -> `10.\t`).

shiftOwnLines now takes the new content column and moves each own line's
item boundary exactly, leaving the bytes past it untouched.
contentColumnFromMarkerLine computes the CommonMark content column of a
rewritten marker line for both callers. The Tab/Shift-Tab planners keep
their original whitespace materialisation (coupled to their caret math).
…t it

Two follow-ups to the boundary-based own-line shift:

- the old boundary came from the tree-based contentColumnOf while the
  new column came from the CommonMark marker-line rule. They disagree
  when an item's content is indented code, so a same-width renumber
  moved the code's lines. Both sides and the line classification now
  use contentColumnFromMarkerLine on the marker line.
- a tab just past the boundary kept its byte but not its width once
  shifted, pushing a nested child into indented code. Structural
  whitespace between the boundary and the line's content now rewrites a
  tab whose width would change as the spaces it occupied; code payload
  (CodeText) bytes stay untouched.
…n payload

Replace the piecemeal tab handling in shiftLine with one rule. Past the
item's content boundary, walk the line's structural prefix (whitespace
plus nested ListMark / QuoteMark tokens) and rewrite any tab whose width
would change at the shifted column as the spaces it occupied, so nested
markers and their children keep their columns. Verbatim payload is
never touched: the walk stops at CodeText, and continuation lines of an
HTMLBlock, CommentBlock or ProcessingInstructionBlock shift only the
list prefix.

Nodes are resolved in the Markdown tree with resolve(), not
resolveInner(): the latter enters a labelled fence's language overlay
and never reaches the Markdown CodeText.
…d code

Two gaps in shiftLine's payload detection:

- an HTML / comment / processing-instruction continuation line stopped
  the structural walk at the shifted item's boundary. When the block
  belongs to a deeper list item, the whitespace up to that item's content
  column is structural too; a tab there changed width and pushed the
  block out of the nested item. The walk now stops at the content column
  of the innermost list item that owns the block.
- a tab directly before CodeText (the separator after `>` in a quoted
  fence) was expanded to spaces, which reparse as code payload. That tab
  is now left as-is.
The guard that leaves a tab directly before CodeText untouched also hit a
nested list's structural indent tab, so after a marker widened the fenced
code fell out of the nested bullet into an indented code block. Limit it
to the tab that pads a QuoteMark; any other tab goes through the normal
width adjustment.
@mtskf
mtskf merged commit 382ef72 into main Nov 20, 2026
2 checks passed
@mtskf
mtskf deleted the fix/list-enter-renumber-keeps-children branch November 20, 2026 06:21
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.

1 participant