Skip to content

fix(list): keep a quote-padding tab's width when a list shift moves the quote - #595

Open
mtskf wants to merge 5 commits into
mainfrom
fix/quote-fence-tab-literal
Open

mtskf wants to merge 5 commits into
mainfrom
fix/quote-fence-tab-literal

Conversation

@mtskf

@mtskf mtskf commented Dec 4, 2026 •

Copy link
Copy Markdown
Owner

Summary

List Tab / Shift-Tab (and the Enter split) changed the code literal of a quoted fence when a code line's tab sat right after >. That tab is partly quote padding: CommonMark consumes one column of it and keeps the rest of its width as code spaces, so it must keep its width, not its byte.

Changes

  • shiftLine (src/webview/cm/list/list-transform.ts): drop the special case that kept a tab right after a QuoteMark as a byte. The tab now goes through the ordinary prefix path (expanded only when its width would change). Code tabs past the padding still stay bytes via the existing CodeText / inMeasuredIndent rule.
  • inMeasuredIndent reads its columns from the fence container's content column on each line (new containerContentColumn, read per line through the container chain: Blockquote = after its own > + 1 padding column, ListItem = as far past its parent's content as on its marker line, so a list inside a quote with a misaligned > is measured correctly). The fence indent is measured inside quotes too, as the opener's indent relative to its quote content (before, "never inside a quote" changed the literal when the fence was indented).
  • inMeasuredIndent: the closing-fence-run rule is now a threshold check. A tab on a code line that is a fence run keeps its width only when keeping its byte would leave the run under 4 columns past its container's content (Blockquote: after > + 1 padding column; ListItem: item content column). Before, every width-changing tab there was expanded, which (once the quote-padding tab no longer short-circuited) turned a code tab into spaces irreversibly on Shift-Tab → Tab (found in review).
  • New test helper codeLiterals (test/webview/helpers/list-structure.ts): commonmark.js code_block.literal for every code block. lezer's CodeText range cannot show a partly consumed tab, so it is the oracle for code preservation.
  • cm-list-indent-keymap.test.ts: Tab and Shift-Tab pinned against that oracle for >\tx, >\t\tx, and the fix: keep a fence-like code line inside an unclosed fence on list Tab / Shift-Tab #582 shape 1 (> \tx, switched from the CodeText slice pin).
  • cm-list-continuation-keymap.test.ts: the fix(list): keep nested children under the new item when Enter splits a list item #506 Enter-split pin (>\t\treturn) switched to the same oracle; it was hiding the same bug (literal " \treturn" became " \treturn").

Related

  • TODO: list の Tab / Shift-Tab で、quote 内 fence の > 直後の tab が code literal を変える

Test Plan

  • Red before / green after: with the new tests on the old list-transform.ts (checked in a throwaway worktree), 5 fail — Tab and Shift-Tab for >\tx ("x\n" → " x\n", " x\n" → "x\n") and >\t\tx ("\tx\n" ↔ " \tx\n"), plus the Enter split (" \treturn\n" → " \treturn\n"). Shape 1 stays green on both, as fix: keep a fence-like code line inside an unclosed fence on list Tab / Shift-Tab #582 decided.
  • Renumbered follower (8. first\n9. second\n > ~~~\n >\t\tx…, Enter after fi): fails on origin/main (" \tx\n" → " \tx\n"), passes now.
  • Closing-fence-run threshold, expanding side: Tab widens a quoted fence-run code line's tab when its byte would close the fence and the existing Shift-Tab keeps a fence-like code line of an unclosed fence as code.
  • Round-trip table (Shift-Tab then Tab, literal + run CodeText after each): quoted no-fence-indent and unquoted rows fail on origin/main; the quoted one-column-fence-indent row fails on the intermediate head 844d0a9, and the two list-inside-quote rows fail on a0533ba. The Enter split / follower tests also pin that the quoted fence stays with 10. … (blockOwner). Tab / Shift-Tab table also pins that B still owns the quoted fence (blockOwner).
  • After the fix: vitest run test/webview/list/ 1163/1163 pass, pnpm lint and pnpm compile clean at d7140fc.
  • E2E not run: webview-only editing transform, no host, protocol or E2E-covered path touched.

mtskf added 5 commits December 4, 2026 16:22
…he quote

A tab right after `>` is partly quote padding: CommonMark consumes one
column of it and keeps the rest as code spaces. shiftLine kept that tab
as a byte, so Tab / Shift-Tab / Enter-split changed the quoted code
literal whenever the tab's width changed. It now keeps its width like any
other prefix tab. Tests judge code by commonmark.js's literal, which
lezer's CodeText range cannot show.
… stays code

The closing-fence test is a threshold (4+ columns past the container's
content), so expanding every width-changing tab on such a line was more
than needed: inside a quote, Shift-Tab then Tab turned a code tab into
spaces for good. Expand it only when keeping the byte would drop the
line below the threshold.
CommonMark strips the fence indent relative to the container content, so
inside a quote a tab overlapping that indent is measured too. Read both
the fence indent and the closing-run threshold from the container's
content column on each line.
…ner chain

A list inside a quote can have its `>` at a different column on each
line, so the item's absolute content column from its marker line is
stale on other lines. Read each container's content column per line:
a quote past its own `>`, an item as far past its parent's content as on
its marker line. Also pin that the quoted fence stays with its item
after an Enter split and a follower renumber.
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