feat(outline): outline type + outliner — S3 (#109)
CI / ci (push) Canceled after 0s

Dedicated block surface (ADR-0013, #105 variant B): OutlineTree
parses/serializes plain nested-bullet markdown leniently and
normalizes on save; the outliner promotes one NSTextView over the
focused row with LogSeq-style keys (Tab/⇧Tab, ⌥↑/⌥↓ subtree move,
↑/↓ hop, ⇧↑/⇧↓ block selection, ⌘↑/⌥↓ fold, Enter split), folds
session-scoped by runtime node UUID. New Outline ⇧⌘N stages a
type: outline draft through the existing autosave/conflict
machinery; reading renders the serialized markdown unchanged.

Outline rows use the body face at its natural line box — the prose
CSS-1.8 lineHeightMultiple grew the focused row and detached the
bullet (test-pinned). Finish-audit fixes included: paste-multiline
sanitizing at setText, dead Enter disjunct, dead Row.path.

Closes #109
This commit is contained in:
AlexKucera committed 2026-10-15 13:09:31 +02:00
1 parent e55747e7fe
commit c23ee0f62f
21 files changed
+1809 -21

No files matched your search

@@ -0,0 +1,78 @@
# Issue #109 — Outline type + outliner: block tree, LogSeq keys
> **Date:** 2026-10-15
> **Type:** issue
> **Reference:** Gitea AlexKucera/Museion issue #109 (map #97; ADR-0013; #105 verdict variant B)
## Goal
Build S3 of the outliner: an outline content type (`type: outline` frontmatter) and a dedicated block outliner surface with LogSeq-style keys — parse/serialize a plain nested-bullet markdown file, structural ops (indent/outdent/move/enter), fold, block selection, and routing through the existing draft/session machinery.
## What Was Done
- **`Museion/OutlineTree.swift`** (new, nonisolated pure) — `OutlineNode` (runtime UUID identity, single-line text, children) + `OutlineTree.parse/serialize` over the one-file plain nested-bullet format. Lenient parse (`-`/`*` markers, any whitespace indent, tab = 2 spaces, depth jump clamps to prev+1, verbatim preamble before first item), canonical serialize (2-space + `- `, no trailing newline). Path-addressed structural ops returning new path or nil on boundary no-op: `indent`, `outdent`, `move(up:)` with parent-crossing (LogSeq-style: up lands before the parent, down after), `siblingMove(up:)` (sibling-only, for batches), `enter(caretOffset:)` with `EnterResult` (split at caret / empty-at-depth outdents / empty-root new sibling).
- **`Museion/OutlineEditorView.swift`** (new) — `OutlinePresenter` (nonisolated pure: visible-rows projection with fold skipping, id↔path/node, `setText` by identity with newline sanitizing, `rangeIDs` block-selection span, `applyBatch` sibling-only batch ops with boundary-leader no-op) + `OutlineEditorView` (SwiftUI chrome: fold-toggle bullets, per-depth 1px rails, "⋯ N" fold counts, rust caret) + `OutlineRowTextView`/`RowTextView` (ONE promoted borderless NSTextView on the focused row; structural key interception in `keyDown`).
- **Key set** — Tab/⇧Tab indent/outdent · ⌥↑/⌥↓ move subtree (single-node crosses parents; batches sibling-only) · ↑/↓ hop visible blocks · ⇧↑/⇧↓ extend block selection · ⌘↑/⌘↓ fold/unfold · Enter split/outdent/sibling · Esc collapses block selection (via local NSEvent monitor — SwiftUI hosting swallows Esc; probe-pinned).
- **Substrate threading** — `PostStore.writeNew(body:project:type:home:)` (default `.post`; `importFile` explicit `.post`), `PostDraft.type` + `newOutline()` staging a `"- "`/`.outline` draft, `NewOutlineButton` (⇧⌘N) in the File menu, `PostEditorView.outline` flag routing to the outliner, `PostsPaneView` passing `draft.type == .outline` / `lastDraftWasOutline || posts-lookup` for sessions.
- **Tests** — `OutlineTreeTests` (10 pins), `OutlinePresenterTests` (6), `EscEventProbeTests` (the SwiftUI Esc-swallow probe), `PostStore`/`PostsModel`/`ReadingPresenter` extensions (nested-bullet reading pin: apex emits bare `<li>intro\n<ul>` — no `<p>` wrappers).
- **Finish-audit fixes** — paste-multiline data loss (setText flattens `\r\n`/`\n`/`\r` to single space at the one seam; round-trip pin), dead `String(NSCarriageReturnCharacter)` Enter disjunct (evaluates to `"13"` — never matches), dead `Row.path` field removed, duplicate DOX bullet removed.
- **Polish round (user-reported visual jank)** — the live row was reusing the prose paragraph style (CSS `--lh 1.8` calibrated `lineHeightMultiple`), inflating the focused row's line box: oversized caret, row growth 27→37, glyphs parked at fragment bottom, bullet detached. Now: `ProseTypography.outlineRowAttributes` (body face, natural line box), static rows on the same NSFont (no face swap on focus), live row mirrors staticText's `.padding(.vertical, 3)`, `sizeThatFits` floor 21 so textview+padding = 27 = bullet-cell height — no focus jump. User-verified in three rounds ("perfect").
- **DOX** — root/Museion/MuseionTests AGENTS.md entries for every new file and contract.
## Decisions & Rationale
| Decision | Rationale |
|----------|-----------|
| Dedicated block surface (variant B), not markdown-mode | #105 verdict; prototype `ref/prototypes/wf105-outline-editor-prototype.html`; ADR-0013 |
| Lenient parse / canonical serialize / normalize on save | User-confirmed grilling verdict: hand-edited files parse; our writes are canonical |
| Fold = runtime UUIDs, session-scoped, never persisted | Fresh open = all unfolded; folding never dirties the document |
| Text-only undo, block-granular selection | #105 verdict; structural undo excluded from v1 |
| Batch moves sibling-only; single-node ⌥ moves cross parents | User-requested LogSeq behavior; a crossing batch tears itself apart — run-as-unit guard |
| `PostDraft.mountID` remount | Outliner seeds its tree once per mount; same-identity draft swap kept a stale tree |
| Natural line box for outline rows (no CSS 1.8 multiple) | Outliner chrome assumes one row height; an inflated fragment grows the focused row and detaches the bullet. Editing parity lives in the face, not the leading |
| Esc = drop block-selection highlight | Agent's design call (ticket silent); fold is ⌘↑/⌘↓ |
## Gotchas & Fixes
| Problem | Root Cause | Fix |
|---------|------------|-----|
| Oversized caret, row growth, bullet detach on focus | Live NSTextView carried the prose CSS-1.8 `lineHeightMultiple` | `outlineRowAttributes` — natural line box; test-pinned |
| Text face swapped on focus | Static rows used `.system(size: 17, design: .serif)`, live row Valkyrie | Both render `ProseTypography.bodyFont` |
| Text jumped up ~3pt on focus | Live row had `+6` fudge in `sizeThatFits`, static rows `.padding(.vertical, 3)`, HStack top-aligned | Same `.padding(.vertical, 3)` on the live row, fudge removed |
| Whole line jumped on focus | Row totaled 27 floor + 6 padding = 33 vs static 27 | Floor 21 → total exactly 27 |
| Pasted multiline text silently lost lines | Embedded `\n` serialized as stray prose; next parse drops strays | setText flattens CRLF/LF/CR to a space at the seam |
| Dead Enter disjunct `String(NSCarriageReturnCharacter)` | Evaluates to `"13"` (decimal-description trap, same as arrows) | Match `"\r"`/`"\n"` literals |
| Swift Testing compile error in `#expect(outNodes[1...].allSatisfy(\.children.isEmpty))` | Macro + keypath-as-function on a slice infers throwing | Named-parameter closure `{ node in node.children.isEmpty }` |
| ⇧⌘N keystroke unreliable in automation | macOS system handling | Menu item "New Outline" works; smoke via File menu |
## Files Changed
| File | Change Summary |
|------|---------------|
| `Museion/OutlineTree.swift` | new — tree model, parse/serialize, structural ops |
| `Museion/OutlineEditorView.swift` | new — presenter, SwiftUI surface, RowTextView key interception |
| `Museion/ProseTypography.swift` | `outlineRowAttributes` (natural line box) |
| `Museion/PostStore.swift` | `writeNew` type param, stamped first in block |
| `Museion/PostsModel.swift` | `PostDraft.type`/`mountID`, `newOutline()`, `lastDraftWasOutline` |
| `Museion/MuseionApp.swift` | `NewOutlineButton` ⇧⌘N |
| `Museion/PostEditorView.swift` | `outline` flag → surface swap |
| `Museion/PostsPaneView.swift` | draft/session outline routing |
| `MuseionTests/OutlineTreeTests.swift` | new — 10 tree pins |
| `MuseionTests/OutlinePresenterTests.swift` | new — 6 presenter pins |
| `MuseionTests/EscEventProbeTests.swift` | new — Esc delivery probe |
| `MuseionTests/PostStoreTests.swift` | writeNew type, import-stays-post pins |
| `MuseionTests/PostsModelTests.swift` | newOutline/saveDraft lifecycle pins |
| `MuseionTests/ReadingPresenterTests.swift` | apex nested-bullet list pin |
| `MuseionTests/ProsePresenterTests.swift` | natural-line-box pin |
| `AGENTS.md`, `Museion/AGENTS.md`, `MuseionTests/AGENTS.md` | DOX entries |
## Open Items & Next Steps
- [ ] Second map (#102): drag-reorder, zoom-into-block — explicitly out of v1 scope
- [ ] MEDIUM-2 (deferred, audit): external mixed-content outline files lose non-bullet lines on next in-app edit — needs a product decision; follow-up on map #97
- [ ] Mixed-depth batch run half-apply ceiling — ponytail-marked in code with two-pass dry-run upgrade path
- [ ] Mid-word click caret mapping — v1 ceiling (caret lands at end), ponytail-marked
---
*Log written by write-log skill*
+1
View File
@@ -5,6 +5,7 @@ Complete history of session logs in this directory, newest first. One-line summa
<!-- write-log: full-index -->
| Date | Type | File | Summary |
|------|------|------|---------|
| 2026-10-15 | issue | [20261015-issue109-outline-type-outliner_log.md](20261015-issue109-outline-type-outliner_log.md) | #109 outliner: OutlineTree + block surface, LogSeq keys, natural-line-box typography; 170 tests green |
| 2026-10-13 | issue | [20261013-issue108-library-ui-archive-audits_log.md](20261013-issue108-library-ui-archive-audits_log.md) | #108 variant-B library + Archive pane + commands, two audit rounds, fold corrected, 144 tests green |
| 2026-10-13 | issue | [20261013-issue107-storage-substrate-projects-archive_log.md](20261013-issue107-storage-substrate-projects-archive_log.md) | #107 S1: pieces re-rooted to projects/ + archive/, global slugs, type frontmatter; audit dedupe fix |
| 2026-10-12 | issue | [20261012-issue22-import-external_log.md](20261012-issue22-import-external_log.md) | #22 import & external markdown: SessionTarget, guest slot, Origin ask, drag-drop — full suite green |