GeezerVison is showing github.com — fix: #118 順序付きリストの Tab/Shift+Tab で list-aware なインデント+再採番 by ymnao · Pull Request #136 · ymnao/scripta
Conversation
概要
順序付きリストで Tab を押すと子リストが 1. から再採番され、Shift+Tab で親レベルに戻る際も連番が復帰する list-aware なハンドラを listKeymap に追加。CommonMark / @codemirror/lang-markdown / @lezer/markdown の挙動と整合させながら、ネスト時のインデント幅は親項目のコンテンツ列に合わせて動的算出する。
関連 Issue
Closes #118
移行 Stage
該当なし (bug fix [7] フェーズ)
変更内容
コア実装 (src/components/editor/live-preview/lists.ts)
parseListLine で ordered / bullet / task を統一分類し、markerWidth を返却
computeListIndentChanges(state, direction) を pure helper として切り出し:
- 選択行ごとに新インデントを算出 (Tab は親 content offset 揃え / Shift+Tab は ancestor の indent 揃え)
- block 内 ordered 行を walk して renumber map を構築
- marker 桁数が変わる renumber では descendant の indent を cascade shift (continuation paragraph 含む)
findPrevListLine / isBlockMember で CommonMark の lazy continuation を素通り、isParagraphInterrupting で paragraph 中断ブロックを境界化:
- ATX heading / thematic break / blockquote / fenced code
- HTML block (CommonMark §4.6 type 1/6 の block-level tag allowlist)
isInsideOpaqueBlock で HTMLBlock / FencedCode / CodeBlock / IndentedCode / CommentBlock の interior を Tab/Shift+Tab 対象から除外
- 既存
listKeymap (Prec.high) に Tab / Shift-Tab を追加し、リスト外では false を返して既定の indentWithTab にフォールスルー
- 選択終端が次行先頭にある場合は CM 標準
changeBySelectedLine 規約に合わせて終端行を除外
renumber 規則
- 修飾された (Tab/Shift+Tab された) 順序付き行 → 同レベルに既存項目がなければ
1. から再開、既存があれば continuation に合流
- 修飾されていない先頭項目はユーザの起点番号 (5. a 等) を尊重
- bullet / task / blank line / 浅い indent で counter reset
- block scan は paragraph 中断ブロック (heading/hr/blockquote/fence/HTML) で停止
テスト
- ユニットテスト 121 件 (
lists.test.ts): pure helper の決定的検証
- 基本: Tab/Shift+Tab on ordered / bullet / task
- 範囲選択, 選択終端境界
- 親 content offset 動的算出
- marker 桁数 cascade (9→10 / 10→9)
- continuation paragraph (indented / lazy)
- paragraph 中断ブロック (heading/hr/blockquote/fence)
- HTML block (block-level tag は境界 / inline tag は continuation / interior は no-op)
- e2e 4 件 (
list-heading-editing.spec.ts):
- 初期実装の canonical case
- 中間項目の Tab
- 子項目の Shift+Tab
- ユーザ報告シナリオ (連続 Enter で親番号が破綻しないこと)
動作確認
-
pnpm format / lint / typecheck / typecheck:e2e 全 green
-
pnpm test 全 1951 件 (skip 2) green
-
pnpm test:e2e 全 160 件 green
-
pnpm build green
-
pnpm check:legacy-residue ✅
- チャットで報告された複数シナリオ:
- 親番号が
1, 4, 5 のように飛ぶリグレッション → 修正済み
8. a / 1. x / 9. b / 1. child の Shift+Tab で marker 桁数 cascade → 修正済み
- lazy continuation で
3. next が renumber されない問題 → 修正済み
# heading / --- / blockquote / fence / HTML block boundary → 修正済み
- HTML block interior の list 風テキストを誤拾い → 修正済み
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
順序付きリストで Tab を押すと子リストが `1.` から再採番され、
Shift+Tab で親レベルに戻る際も連番が復帰する list-aware ハンドラを追加。
- `parseListLine` で順序付き / bullet / task を統一的に分類
- `computeListIndentChanges` が選択行に対して indent + renumber を計算
- 純粋関数として切り出し、ユニットテストで決定的に検証
- 既存 listKeymap (Prec.high) に Tab / Shift-Tab バインドを追加し、
リスト行でない場合は false を返して既定の indentWithTab にフォールスルー
renumber 規則:
- 修飾された (Tab/Shift+Tab された) 順序付き行で同レベルに既存項目が
なければ `1.` から再開、既存があれば continuation に合流
- 修飾されていない先頭項目はユーザの起点番号 (5. a 等) を尊重
- bullet / task / 空行 / 浅い indent で counter を reset
- フェンス内コードブロックはハンドラ対象外
Closes #118
初期実装は固定 2 スペースでインデントしていたが、`1. ` (コンテンツ
列 3) の下に付けても Lezer は CommonMark の nesting 条件
(indent ≥ 親コンテンツ列) を満たさず sibling と見なして
しまう。その状態で Enter を押すと
@codemirror/lang-markdown の `insertNewlineContinueMarkup` が
`renumberList` で sibling と見た後続項目を誤って再採番し、
親レベルの番号が `1, 4, 5` のように飛ぶリグレッションが生じていた
(チャットレポート)。
修正:
- `listContentOffset(info)`: 項目の「コンテンツ列」 (indent + marker + space) を計算
- `computeIndentForNest`: 同一 indent の直前 sibling を探しそのコンテンツ列
を newIndent に採用 (`1. ` → 3, `10. ` → 4, `- ` → 2, `- [ ] ` → 6)
- `computeIndentForOutdent`: Shift+Tab では親項目の indent に揃えてアウトデント
- Lezer が正しく nested と認識し、`insertNewlineContinueMarkup` の
`renumberList` が sub-list 内に閉じるようになる
テスト:
- ユニットテストを 3 スペース indent 前提に更新
- チャットで報告されたシナリオのリグレッション e2e を追加
/simplify レビュー 4 並列 (reuse / simplification / efficiency / altitude)
の指摘を集約して反映。挙動は変えず実装の重複・冗長性を解消。
主な変更:
- parseListLine が markerWidth を返すように拡張し、listContentOffset
ヘルパーを削除 (ordered / bullet / task 3 分岐の重複を解消)
- findMarkerRange の重複コードブロックガードを isInsideCodeBlock 経由に
統一 (~10 LOC + 強制 cast 削除)
- findPrevListLine helper を導入し computeIndentForNest / Outdent の
back-walk ループを統合
- Mod.lineFrom フィールドを削除 (未使用; state.doc.line で都度取得)
- indentCounters: Map<string, {next: number}> → Map<string, number>
- [...indentCounters.keys()].filter スプレッド廃止 → 直接 keys() iteration
- 重複 parseListLine 呼び出しを parsedLines キャッシュで吸収
- modMap+renumberMap 直後の Set+sort を廃止し、block iteration 順序を
そのまま採用 (block iteration は元から昇順)
- findMarkerRange を `??` ベースに整理しキャスト削除
- 4 つのマーカー regex / 6 個の冗長 JSDoc を要点のみに圧縮
- テストヘルパー applyChanges / applyChangesWithSelection を統合
挙動不変・全テスト green (unit 1930 / e2e 160)。
`1. a\n2. b\n3. c` で 2. b だけを範囲選択しているつもりでも、
sel.to が "3." の直前 (= line 3 の先頭) になっていると、私の
ループ `for (i = startLineNum; i <= endLineNum; i++)` が
line 3 まで含めてしまい、3. c も子レベルに移動してしまっていた。
CM 標準の `changeBySelectedLine` の規約に合わせ、非空 selection で
sel.to === lineAt(sel.to).from のときは終端行を 1 つ手前まで縮める。
回帰テスト: `EditorSelection.single(doc.indexOf("2."), doc.indexOf("3."))`
で line 3 が対象外となること、3. c が renumber で `2. c` になることを確認。
例: 8. a / 1. x / 9. b / 1. child で Shift+Tab すると
9. b → 10. b に再採番されるが、子 ` 1. child` のインデントが
3 spaces のままだと、CommonMark 上 10. b (content offset 4) の
子として扱われなくなる。
renumber で marker 桁数 (= String(newNum).length - String(oldNum).length)
が変わる ordered 行ごとに、descendant lines (=ブロック内で当該行の
content offset 以上の indent を持つ後続行) を walk してインデントを
delta 分シフトする。
- 正の delta (9 → 10): descendant indent を +1
- 負の delta (10 → 9): descendant indent を -1 (clamp at 0)
- 累積 shift もサポート (ancestor の renumber が複数重なる場合)
- 既に user が newIndents で動かした行は scope 判定にその新 indent を使う
回帰テスト追加:
- 9→10 で descendant が +1 シフト
- 10→9 で descendant が -1 シフト
CommonMark の list item は continuation paragraph (deeper indent
の非リスト行) を内包できるが、これまで以下 3 箇所が即座にリスト
ブロック境界として停止していた:
1. findPrevListLine: 非リスト行で即 null を返していたため、
`1. parent / continuation / 2. child` で 2. child に Tab すると
sibling が見つからず fallback の oldIndent + " " に落ちて、親の
content offset (3) に揃わない indent になっていた。
2. block scan: 非リスト行で blockStart/End を打ち切っていたため、
continuation を含むリストの renumber / cascade 範囲が途中で切れた。
3. cascade walk: list marker 行だけを対象にしていたため、
`9. b → 10. b` で ` 1. child` は +1 されても、その本文行
` note` は shift されず content offset 整合性が崩れた。
修正:
- findPrevListLine に `boundaryIndentLen` 引数を追加し、
leading 幅が境界以上の非リスト行は continuation として skip
- 共通の `leadingWidth` helper を追加
- `isBlockMember` で list line と indented 非リスト行を block 内とみなす
- effectiveIndentLen helper で continuation を含む indent 評価を集約
- cascade walk と emit も continuation の indent shift をサポート
回帰テスト追加:
- "1. parent / continuation / 2. child" で Tab → " 1. child"
- "8. a / 1. x / 9. b / 1. child / note" で Shift+Tab →
child と note が両方とも +1 シフトする
前回の継続対応では findPrevListLine は boundaryIndentLen === 0 のとき
任意の非リスト行を walk-through していたが、isBlockMember だけは
leading 幅が 1 文字以上の場合だけ block 内扱いしていた。両者の判定が
ズレていたため、CommonMark の lazy continuation (un-indented な
パラグラフが直前の list item に属するケース) で:
1. parent
continuation ← col 0
2. child ← Tab
3. next
の Tab で 2. child は 1. parent の content offset (3) に揃って
` 1. child` になる (sibling 探索は OK) が、block scan は
`continuation` (col 0) で打ち切るため `3. next` が再採番されず
残ってしまっていた。期待:
1. parent
continuation
1. child
2. next
marked など CommonMark lexer もこの 4 行を 1 つの ordered list として
token 化するため、実用上 lazy continuation として扱う必要がある。
修正:
- isBlockMember を「任意の非空行 = block 内」に拡張
- renumber walk は元々 if (\!orig) continue で非リスト行を skip するので
counter 状態は壊れない (lazy continuation は無害に素通り)
- cascade walk は indent 比較が col 0 < 親 content offset で短絡するため
un-indented continuation を誤って shift することもない
回帰テスト追加:
- "Tab past a lazy (un-indented) continuation still finds the prior sibling"
- "lazy continuation does not truncate the renumber block
(`3. next` → `2. next`)"
既存 "Tab on item after a continuation paragraph aligns to parent's
content offset" は名前を "Tab past an indented continuation finds the
prior sibling list line" にリネームし、indented と lazy の 2 ケースを
明示的に区別した。
前回の lazy continuation 対応で isBlockMember と findPrevListLine を
「任意の非空行 = block 内」に広げたが、それは過剰で、CommonMark の
paragraph を中断するブロック (ATX heading / thematic break /
blockquote / fenced code) まで list block に巻き込んでしまっていた。
例:
1. a
# heading
2. b
これは list / heading / list の 3 token なのに、現実装では block scan が
`# heading` を素通りし、2. b を 1. a 配下にネスト + renumber 対象に
してしまっていた。
修正:
- `isParagraphInterrupting(text)` helper を追加 (CommonMark §6 の
paragraph 中断条件を判定):
- ATX heading: `#` to `######` 後に space または EOL
- Thematic break: 3+ の `-`, `*`, `_` (バックリファレンスで同一文字に限定)
- Blockquote: `>`
- Fenced code: ``` ``` ``` or `~~~`
- `isBlockMember` で paragraph 中断行を block 外に倒す
- `findPrevListLine` でも paragraph 中断行に当たったら walk 停止
これにより lazy continuation (plain paragraph text) は block 内のまま、
heading / hr / blockquote / fenced は確実に境界になる。
回帰テスト追加 (5 件):
- ATX heading between list items
- thematic break between list items
- blockquote between list items
- fenced code block between list items
- "3. c" after heading-severed block keeps user-typed number
CommonMark §4.6 のタイプ 1〜7 をひとまとめにする HTML_BLOCK_RE を
isParagraphInterrupting に追加。`<\!--` / `<\![CDATA[` / `<\!` / `<?` /
`<` 後にタグ名の 5 パターンで判定する。
例:
1. a
<\!-- comment -->
2. b
は marked では list / html / list の 3 token なのに、これまでは
HTML block を lazy continuation として素通りし、2. b に Tab すると
1. a の sibling に誤認していた。本コミットでこれが境界として正しく
扱われるようになる。
regex は意図的に lenient: `<3` のような稀な擬陽性を許容する代わりに
コメント・宣言・要素タグをすべて確実に拾う。
回帰テスト追加:
- "1. a / <\!-- comment --> / 2. b" 境界
- "1. a / <div>x</div> / 2. b" 境界
- "1. a / <table>... / 2. b" 境界
CommonMark §4.6 type 6 は厳密には closing tag (</tag>) も block opener
として扱うが、この repo の markdown parser である marked は単独の
closing tag を直前 list item の text として continuation 側に残す:
1. a
</div>
2. b
3. c
は marked では 1 つの ordered list として token 化され、2. b / 3. c は
1. a の sibling になる。
前回追加した HTML_BLOCK_RE は `\/?[a-zA-Z]` で closing tag も拾って
いたため、2. b に Tab したときに </div> を block boundary と誤認し、
1. a を sibling として見つけられず誤った fallback indent (2 cols)
+ 3. c の renumber 漏れになっていた。
修正:
- HTML_BLOCK_RE の `\/?` を削除し opening tag のみを境界対象とする
- 単独 closing tag は lazy continuation として block 内に残る
回帰テスト追加:
- "1. a / </div> / 2. b / 3. c" で Tab → "1. a / </div> / 1. b / 2. c"
(sibling 探索が </div> を素通り、block scan が 3. c まで延伸)
…llowlist に絞る
これまでの HTML_BLOCK_RE は opening tag を「任意のタグ名」で境界扱いして
いたため、<span>, <a>, <em> 等の inline HTML tag まで paragraph
interrupt と誤判定していた。@codemirror/lang-markdown はこれらを
inline content として扱うため、
1. a
<span>inline</span>
2. b
3. c
は全体が 1 つの OrderedList。現行では 2. b に Tab したとき 1. a を
sibling として見つけられず、親 content offset (3) ではなく fallback
の 2 columns に落ちていた。
修正:
- HTML_BLOCK_TAGS Set を導入 (CommonMark §4.6 type 1 + type 6 の
block-level tag 完全リスト)
- HTML_OPENER_RE: <\!-- / <\![CDATA[ / <\! / <? は常に境界
- HTML_TAG_RE: <name 後に space/>/EOL/`/` が来る opening tag を抽出し、
allowlist にあるもののみ境界扱い
- inline tag (span, a, em, code, strong, button, ...) は素通り
- 既存の `<div>` / `<table>` / `<\!-- comment -->` 境界テストは
そのまま green を維持
回帰テスト追加:
- "1. a / <span>inline</span> / 2. b / 3. c" で Tab → sibling 解決して
"1. a / <span>... / ` 1. b / 2. c"
- "1. a / <a href=\"x\">link</a> / 2. b / 3. c" でも同様
isInsideCodeBlock は FencedCode / CodeBlock / IndentedCode しか
除外していなかったため、@lezer/markdown が HTMLBlock 内部と判定
する行でも parseListLine が拾ってしまっていた。たとえば:
<div>
2. b
</div>
の中央行は Lezer 視点では HTMLBlock interior (HTML body) であり
markdown list item ではない。これまでは Tab で内部行を 1. b に
再採番してしまう余地があった。
修正:
- OPAQUE_BLOCK_NAMES Set を新設し HTMLBlock / CommentBlock /
ProcessingInstructionBlock も追加
- isInsideCodeBlock → isInsideOpaqueBlock にリネーム
- 主ループ (選択行の filter) / findPrevListLine / isBlockMember /
findMarkerRange すべてで isInsideOpaqueBlock を参照
- HTML/code block 内部の list 風テキストは Tab/Shift+Tab の対象外、
walk-back/forward の hard boundary になる
CommonMark §4.6 type 6 は HTMLBlock の end condition を「blank line」
と定めており @lezer/markdown もそれに従う。`<div>x</div>` の直後に
blank なしで `2. b` を置くと parser 視点では `2. b` まで HTMLBlock
interior なので、既存の "HTML 境界" テストは blank line を挿入する
形に更新した。"標準閉じタグが marked では continuation" 旨の
回帰テストは Lezer の view (CommonMark spec) と矛盾するため、
spec 通り HTMLBlock を開始する挙動を期待するテストに置き換えた。
回帰テスト追加 (3 件):
- "<div>\n2. b\n</div>" で Tab no-op
- "<div>\n 2. b\n</div>" で Shift+Tab no-op
- "1. a / </div> / 2. b / 3. c" で Tab no-op (closing tag が HTMLBlock 開始)
更新テスト (3 件):
- "<div>x</div>" / "<table>" 境界テストに blank line を追加
- "sibling search treats HTML block interior as hard boundary" を
blank line ベースで CommonMark 準拠の挙動に変更
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
ymnao
added a commit
that referenced
this pull request
Jun 5, 2026
- Fixed にバグ修正クラスタをロールアップ追記 (#116 #117 #120 #124 #130 #131 #132 #134 #135 #136 #137)
- Added に手動アップデートチェック (#98 → #138) を追記
- Dependencies を Phase α 反映の実バージョンに更新
(electron 42.3.3 / biome 2.4.16 / zustand 5.0.14 / js-yaml 4.2.0 /
dompurify 3.4.8 / marked 18.0.4 / lucide-react 1.17.0 /
@codemirror/view 6.43.0 / vite 8.0.14 / vitest 4.1.7)
- リリース日を _(unreleased)_ に、旧リポ表記を scripta-tauri (private) に、
footer URL を ymnao/scripta に修正
Co-Authored-By: Claude Opus 4.8 <[email protected]>
ymnao
added a commit
that referenced
this pull request
Jun 5, 2026
* release: v0.2.0
- package.json:version 0.0.0 → 0.2.0
- CHANGELOG.md 新設(旧 Tauri 版から Electron への完全書き直し版として
Added / Changed / Fixed / Dependencies / Security / 既知の制限 を記載)
closes #27
* docs: v0.2.0 リリース運用注釈と README の表現を release-ready に更新
レビュー指摘反映:
- README.md: "v0.2.0 を予定" / "リリース後 ... 取得できる予定" を
リリース後にも valid な表現へ書き換え(merge → tag push 後に
Releases ページが publish される前提)
- docs/parity-checklist.md § 12: 「必須 4 項目は tag push 前に
手動検証で pass させ、検証ログを Release Notes に追記する」
というリリース運用を冒頭に明示
* docs: CHANGELOG リリース日と parity-checklist リリース運用を実態に合わせる
レビュー指摘反映:
- CHANGELOG.md: リリース日を 2026-05-13 → 2026-05-14 (publish/tag 日に揃える)
- docs/parity-checklist.md § 12: release.yml が tag push 後に
draft Release を `--generate-notes` で自動生成する流れに合わせ、
「Release Notes 追記 → tag push」を「tag push → draft 自動生成
→ 生成された draft に検証ログ追記 → publish」の正しい順序へ修正
* docs: CHANGELOG を v0.2.0 リリース内容に更新
- Fixed にバグ修正クラスタをロールアップ追記 (#116 #117 #120 #124 #130 #131 #132 #134 #135 #136 #137)
- Added に手動アップデートチェック (#98 → #138) を追記
- Dependencies を Phase α 反映の実バージョンに更新
(electron 42.3.3 / biome 2.4.16 / zustand 5.0.14 / js-yaml 4.2.0 /
dompurify 3.4.8 / marked 18.0.4 / lucide-react 1.17.0 /
@codemirror/view 6.43.0 / vite 8.0.14 / vitest 4.1.7)
- リリース日を _(unreleased)_ に、旧リポ表記を scripta-tauri (private) に、
footer URL を ymnao/scripta に修正
Co-Authored-By: Claude Opus 4.8 <[email protected]>
---------
Co-authored-by: Claude Opus 4.8 <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
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.
|