perf(editor): scope fold re-key to the edit (#142)
CI / ci (push) Canceled after 0s

With a fold open, every keystroke re-scanned the buffer, rebuilt the
full attributed string through setAttributedString (invalidating
TextKit layout for the ENTIRE document — O(n²) typing on folded
documents), and rasterized a chrome image the size of the document
(~35M pixels on a 700×50,000pt doc) to paint a handful of chevrons.

Single-line edits now re-key folds in place: a shouldChangeText
override records the edit (range + UTF-16 delta) and a pure rekey
function shifts surviving folds, kills folds whose marker line was
edited (un-hiding just that scope), and re-hides a line edited inside
a hidden scope — no parents rescan, no storage swap. Structural
edits, multi-line pastes, and wholesale loads keep the full pass; a
font probe at each survivor's scope head falls back to it whenever
hidden styling was wiped (the fence-flip restyle self-heals this way).

Chrome renders as one tiny cached layer per list parent (same glyph
rasters at ~15×18pt, geometry-flipped into the existing document-space
overlay) instead of the document-sized bitmap; an edit at/after every
parent line skips the rebuild outright, so writing at the document end
does zero geometry queries. Full-buffer scans per keystroke drop from
2–3 to one.

Finish-audit hardening: the single-line gate checks Character.isNewline
(a literal newline compare passes CRLF — one grapheme equal to neither
scalar), and apply() clears the recorded edit so structural indent/
outdent always takes the full pass (a childless unterminated block's
shift-tab is a single-line replacement that would otherwise keep a
dead fold's scope hidden — apparent line loss).

Closes #142
This commit is contained in:
AlexKucera committed 2026-11-03 10:40:14 +01:00
1 parent de1154dacd
commit cc317b65b9
9 files changed
+687 -114

No files matched your search

+4
View File
@@ -74,6 +74,10 @@ All notable changes to this project will be documented in this file. The format
- **skills:** Craft canon distilled from the #4 shortlist — rhetoric (Heinrichs: argument and rhetoric, ten cards plus the fallacy index), reader-psychology (Williams: the reader-processing diagnosis sequence), prose-craft (Clark: fifteen generative tools across better-words, structure, humor, revision); a sample Pass demonstrates all three firing as fix cards (issue #7)
- **skills:** Titles-and-hooks craft skill distilled from web sources per the #4 research — the title surface (takeaway over label, bounded numbers, the worn tease, mode fit, person over committee voice) and the hook's curiosity gap (open it, foot it, honor the title–hook contract), every rule data-backed; the sample Pass gains a ninth fix card demonstrating the shelf (issue #11)
### Changed
- **editor:** Typing beside an open fold no longer rebuilds the whole document (#142) — with a fold live, every keystroke used to re-scan the buffer, rebuild the full attributed string (invalidating TextKit layout document-wide → O(n²) typing on folded documents), and rasterize a chrome image the SIZE OF THE DOCUMENT (~35M pixels on a tall doc) to paint a handful of chevrons. Single-line edits now re-key folds in place (pure delta math: shifts, marker-line deaths, scope re-hides) with no rescan and no storage swap; structural edits, multi-line pastes, and wholesale restyles keep the full pass, and a font-probe fallback self-heals any restyle that wipes the hidden styling. Chevrons/⋯N render as one tiny cached layer per list parent instead of the document-sized bitmap, and an edit below every parent skips the chrome rebuild outright. Finish-audit hardening: the single-line gate is `isNewline` (a literal `"\n"`/`"\r"` compare passes CRLF — one grapheme equal to neither), and structural indent/outdent always takes the full pass (a childless unterminated block's ⇧⇥ is a single-line edit that would keep a dead fold's scope hidden). Fifteen fold/rekey tests incl. a flip-verified audit cycle; suite 570 (issue #142)
### Fixed
- **mentor:** live passes no longer read as crashes — `session/prompt` waits pass-length (1800 s, not the 15 s request default that abandoned working turns with a false "connection lost"), a liveness row shows the engine thinking, Stop stays for the whole turn, and a missing `stopReason` never advances a pass