Repository navigation
fix(list): keep nested children under the new item when Enter splits a list item - #506
Merged
Merged
Conversation
…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.
…er-keeps-children
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 intoshiftLine/shiftOwnLines, now the single implementation shared byrenumberRun, the Tab/Shift-Tab planners (materialiseLineDeltas) and Enter.shiftLineinserts spaces after the line's existing leading whitespace instead of atline.from: a space prepended before a tab is absorbed by the tab stop and moves nothing (the same latent bug existed inrenumberRun). 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) bynewContentCol - oldContentCol, in the same single transaction as the insert and the renumber.Related
Test Plan
test/webview/list/cm-list-continuation-keymap.test.tscheck 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.line.fromturns the tab case red.pnpm compile, Biome,test/webview/list+test/markdown(711 tests) green.pnpm vitest runlocally: 3shell.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-markdownlinear-time) fail only under full-suite load and pass alone.🤖 Generated with Claude Code
https://claude.ai/code/session_01XMxzpbEvcdCeRd6i7DTsvt