Spike B: NSTextView/TextKit2 with custom attributes #53
Notifications
Due Date
No due date set.
Blocks
Depends on
#55 Verdict: substrate decision + ADR-0010
AlexKucera/museion
#51 Spike corpus: pin the eight posts as markdown
AlexKucera/museion
Reference: AlexKucera/museion#53
Reference in new issue
Block a user
Part of #16
Blocked by: 51
Question
What does NSTextView/TextKit2 with custom attributes actually cost, and what does it buy? Throwaway SwiftUI spike on
spike/editor-presentationinspike/textkit2/, editing the calibration piece.PERF-3k.md, note any hitching (layout invalidation on attribute runs is the known risk).[Generated by AI]
Corpus is pinned (#51):
spike/prose/onspike/editor-presentation@3b3544e. Note: the calibration piece has no blockquote/italics in the source — its epigraph is plain prose in curly quotes. Full inventory + word counts in the #51 resolution.[Generated by AI]
Spike B resolution — NSTextView/TextKit2 with custom attributes
Code:
spike/textkit2/onspike/editor-presentation(dd3542a). Run:spike/textkit2/run.sh(wraps the SPM binary in a.app— bare SwiftPM executables never materialize SwiftUI windows).Verdict criteria checklist
Markdown presentation via custom attributes — PASS.
##,**) dimmed gray monospace, fixed 640pt measure (~70 chars). Screenshot:spike/textkit2/assets/spikeB-calibration.png.[NSAttributedString.Key: Any]mapping applied per line kind — no layout manager surgery, no third-party dependency.Reading toggle — PASS (with one renderer caveat).
Text(AttributedString(markdown:)). Screenshot:spike/textkit2/assets/spikeB-reading-final.png.inlineOnlyPreservingWhitespace, so block markers (##) stay literal in reading mode. Switching the parse to.fullmade the app launch with four 30px broken windows — reproducible, reverted. Whatever renderer the real app picks needs a proper harness; the spike's cheap conclusion is only "a separate read-only view is trivial, keep rendering cheap."Editing feel — PASS.
## …became a bold heading instantly (screenshot:assets/spikeB-typed2.png). Undo after in-textDidChangere-attribution is clean — ⌘Z removed the typed line with no garbling (assets/spikeB-undo.png). IME/selection native because it is NSTextView.Performance on PERF-3k (3,452 words) — PASS.
attribute()load: 0.0–1.1 ms (readout in toolbar).--check).assets/spikeB-perf-typed.png). Per-paragraph reattribute keeps invalidation local — the feared full-document attribute-run re-layout didn't materialize at this corpus size.Anchor feasibility — one sentence as asked: quoting-match anchors are trivially feasible in TextKit2 — normalize whitespace, tokenize, and
scrollRangeToVisiblethe found NSRange; the full proof lives in Spike A.Stale anchor UX — PASS. Deleted-text quote → nil → alert with the exact web-proto wording ("Anchor not found / The Post changed after this Fix Card was issued; no text was selected or changed."), screenshot
assets/spikeB-stale2.png.Findings worth carrying into the verdict
~/Library/Saved Application State/de.babylondreams.museion.spike-b*if the window is a stub.Correction to the Reading-toggle caveat above: the "
.fullbreaks window creation" claim was an AX misread (System Events reported 0 windows while the window was visibly on screen — the user confirmed). Retracted.What was actually wrong with the single-
Text.fullapproach: it flattens block structure (headings render body-size, lines run together) and leaves presentation intents unstyled. The follow-up (d836083) renders reading mode per block: blank-line split, strip#prefixes for heading level, inline-markdown-parse each paragraph, font headings bold serif by level. Markup now fully hidden;--checkasserts no#leaks into the reading view. Screenshot refreshed:spike/textkit2/assets/spikeB-reading-final.png.This is the renderer stance the ADR should carry: block-aware rendering, not a monolithic markdown dump.