GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — refactor: live-preview の共通 helper 集約 + collectCodeRanges cache 化 (#209 ②) by ymnao · Pull Request #278 · ymnao/scripta

Conversation

@ymnao

@ymnao ymnao commented Jul 4, 2026

Copy link
Copy Markdown
Owner

概要

live-preview の 13 デコレーションで共通していた「visibleRanges × tree.iterate」パターンと IME composing check を helper に集約、collectCodeRanges を StateField cache 化する。#209 backlog の項目 ② 対応。

関連 Issue

refs #209 (項目 ②)

移行 Stage

該当なし (内部 refactor、Stage 6 相当の運用補強)。

変更内容

新規 helper (src/components/editor/live-preview/plugin-utils.ts)

  • iterateVisibleSyntax(view, enter) — for-of (visibleRanges) → tree.iterate({from, to, enter}) を集約。第 2 引数 ctx: { tree, from, to } は enter 呼び出し中のみ有効な shared object (loop 外で 1 個 hoist、node ごとの allocation を回避)
  • handleComposingUpdate(update, target) — if (update.view.composing) { if (docChanged) map; return; } を集約。atomicRanges を持つ target (lists.ts) にも対応

13 デコレーションに適用

blockquotes / code-block-copy / code-blocks / emphasis / headings / horizontal-rules / images / link-cards / links / lists / strikethrough / wikilinks の buildDecorations と update() を helper 呼び出しに置換。mermaid は StateField ベースで composing check を持たないので対象外。

codeRangesField StateField cache (math.ts)

  • ドキュメント全体の code ranges を tree 変更時のみ再計算するキャッシュ (selection / focus 変化では再計算しない)
  • getCodeRanges(state) helper で field 読み取り + fallback を封じ込め、buildMathDecorations / wikilinks / link-cards の 3 重コピーを 1 呼び出しに集約

/simplify 適用 (別 commit)

  • getCodeRanges helper 集約 (3 重コピー → 1 呼び出し)
  • code-block-copy.ts の buildCopyDecorations に iterateVisibleSyntax 適用漏れを修正
  • iterateVisibleSyntax の ctx object を hoist して mutate (per-node allocation 削減)
  • codeRangesField.update guard を tree identity 比較のみに短縮 (lazy parse 中の無駄計算を回避)
  • plugin-utils.test.ts の dummy sanity test を削除

テスト

plugin-utils.test.ts を新規追加、helper 単体テスト 8 件:

  • iterateVisibleSyntax: multi visibleRanges 対応 / enter = false で子孫 skip / ctx 伝播
  • handleComposingUpdate: composing 分岐 / docChanged 有無 / atomicRanges optional map

動作確認

  • biome check src/components/editor/live-preview/: clean
  • tsc (web / node / e2e): 全 pass
  • vitest: 2233 pass, 2 skipped, 0 fail
  • electron-vite build: 成功
  • 実 Electron e2e (pnpm test:e2e:electron): CI で確認

スクリーンショット

UI 変更なし。

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
ymnao added 2 commits July 5, 2026 00:11
@ymnao
refactor: live-preview の共通 helper 集約と collectCodeRanges cache 化 (#209 …
03ec190
…項目 ②)

- src/components/editor/live-preview/plugin-utils.ts を新規追加。iterateVisibleSyntax
  (visibleRanges × tree.iterate パターン) と handleComposingUpdate (IME composing
  中の decorations map + 早期 return) を集約する
- 13 デコレーションを両 helper で置換 (blockquotes, code-block-copy, code-blocks,
  emphasis, headings, horizontal-rules, images, link-cards, links, lists,
  strikethrough, wikilinks の buildDecorations / update()。mermaid は
  StateField ベースで composing check を持たないので対象外)
- math.ts に codeRangesField (docLength 全体を StateField cache 化) を追加。
  buildMathDecorations / wikilinks / link-cards から重複していた collectCodeRanges
  呼び出しを field 参照に統一し、selection/focus のみの変化では再計算しない
- handleComposingUpdate は lists.ts の atomicRanges にも対応するよう optional
  property を受け取る (target: { decorations; atomicRanges?; })
- plugin-utils.test.ts で iterateVisibleSyntax / handleComposingUpdate の単体テスト
  を追加 (multi visibleRanges / enter=false の子ノード skip / composing 分岐 /
  atomicRanges optional map)

refs #209 (項目 ②)
@ymnao
refactor: /simplify — getCodeRanges helper 集約 / iterateVisibleSyntax …
82123bf
…ctx hoist / 他 3 件

- math.ts: getCodeRanges(state) helper を追加、wikilinks / link-cards /
  buildMathDecorations で 3 重コピーされていた
  `state.field(codeRangesField, false) ?? fallback` を 1 呼び出しに集約 (Reuse/Altitude
  F1)
- code-block-copy.ts: buildCopyDecorations に残っていた for-of / tree.iterate
  パターンを iterateVisibleSyntax で置換 (Reuse F2)
- plugin-utils.ts: iterateVisibleSyntax の ctx object を loop 外で 1 個 hoist し
  per-range で mutate。node ごとの object literal 生成 (O(nodes) × 13 plugins) を
  O(visibleRanges) に削減。ctx は enter 呼び出し中のみ有効という制約を docstring
  に明記 (Efficiency F3)
- math.ts: codeRangesField.update の guard を tree change の identity 比較のみに
  短縮。!tr.docChanged 半分は tree 同一なら redundant なので削除 (lazy parse
  中に docChanged だけ立つケースの無駄計算を回避、Efficiency F4)
- plugin-utils.test.ts: EditorState import の dummy 参照 sanity test を削除
  (createTestState 経由で既に import は使われているので sanity は不要、
  Simplification F5)
@ymnao
ymnao merged commit cb1988f into main Jul 4, 2026
9 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@ymnao
ymnao deleted the refactor/live-preview-helpers-209-2 branch July 4, 2026 15:35
This was referenced Jul 5, 2026
refactor: e2e mock の pure helper を search-pure.ts に統一 (#209 ③) #279
Merged
chore: v0.7.0 リリース準備 #281
Merged
ymnao added a commit that referenced this pull request Jul 5, 2026
@ymnao @claude
chore: v0.7.0 リリース準備 (#281)
9bce21d
- package.json の version を 0.6.0 → 0.7.0 に bump
- CHANGELOG.md に v0.7.0 エントリを追加 (#243 〜 #280)
  - Fixed: FileTree scroll regression (#276)、electron e2e launch teardown timeout 拡大 (#247)
  - Internal: #209 3 項目 (drift-lock 系 refactor #278/#279/#280)、settings setter 集約 (#273 → #277)、search/workspace/backlink 系 helper 抽出 15 件
  - Dependencies: electron 43.0.0 / p-limit 7.3.0 major bump (#275)、Dependabot 7 件 combine (#274)、pnpm-workspace.yaml overrides で @codemirror dual copy を恒久防止

Co-authored-by: Claude Opus 4.7 <[email protected]>
This was referenced Jul 6, 2026
refactor: math / mermaid / table StateField の差分再構築化 + treeChangeDetector 統合 #303
Closed
release: v1.0.0 リリース実施(昇格条件 6 項目すべて pass を確認) #34
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@ymnao
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.