feat(outline): drag-reorder + zoom — S6 (#112)
CI / ci (push) Canceled after 0s

Pointer drag of a block run into any sibling seam or onto a block to
nest as its child (wf113 variant A: fat-gap 30/40/30 bands, seam
line at the future bullet column); the block selection rides the
drag, the moved run becomes the selection, and Esc cancels mid-gesture.
Double-click any bullet zooms to its children with breadcrumbs back
out. New OutlineTree extract/insertRun splice subtrees id-preserving;
the live row's NSTextView moved to OutlineRowTextView.

Audit round: the gesture is self-contained from arm time (strong
window + callback captures — a mid-drag scroll that drops the origin
row cannot strand drag state), a second arming cancels a stuck
predecessor, rowFrames prefers the grip frame, hitTestDrop is y-up
only, and the rails read DropGeometry. Pinned in OutlineDragTests
(monitors fire on sendEvent with a real window number).

[Generated by AI]
This commit is contained in:
AlexKucera committed 2026-10-16 14:49:57 +02:00
1 parent d722820fc8
commit 21e2f27450
14 files changed
+2196 -256

No files matched your search

@@ -0,0 +1,82 @@
# Build S6: outliner interaction II — drag-reorder + zoom-in/focus-subtree
> **Date:** 2026-10-16
> **Type:** issue
> **Reference:** [#112](https://git.babylondreams.de/AlexKucera/Museion/issues/112) (map [#110](https://git.babylondreams.de/AlexKucera/Museion/issues/110), calibrated by P1 [#113])
## Goal
Land S6 of the Outliner II map: pointer drag-reorder of blocks (with subtrees, batch-aware) and zoom-in/focus-subtree in the outline editor, exactly per the wf113 prototype verdict — variant A "fat gaps": seams between rows insert at the following row's depth (the indicator line's left edge = the future bullet column), a row's middle band nests as its last child (ring), invalid targets (own subtree) show a dashed indicator and no-op, and after a drop the moved run IS the selection. Zoom = double-click a bullet roots the projection at that node (depths re-based), breadcrumb/Esc climb back out.
## What Was Done
- **`OutlineTree` drag primitives** — `extract(_:path:)` (remove + return a subtree by path) and `insertRun(_:parentPath:index:in:)` (splice consecutive siblings at any parent, index clamps to append), over a new private `withChildren` accessor. Both path-addressed, id-preserving, like every other op there.
- **`OutlinePresenter` drop math** (pure, in `OutlineDrag.swift` as a `nonisolated extension`): `DropTarget` (`before`/`afterLast`/`lastChild`, all id-referenced), `draggedIDs` (selection rides deduped — a selected ancestor carries its selected descendants), `isValidDrop` (ref at/inside the moving run), `applyDrop` (extract in reverse document order → re-resolve the anchor id in the mutated tree → splice as one contiguous run; no-op drops restore the snapshot and return false), `hitTestDrop` (the fat-gap 30/40/30 bands, ±6 tolerance into the edge rows, y-up window and y-down frames both handled via orientation auto-detect).
- **Zoom in the projection**: `visibleRows`/`rangeIDs` take `zoomRootID` — the walk roots at that node's children with depths re-based to 0; the zoom root's own fold is ignored while it is the root; unknown ids fall back to the whole document.
- **View surface** (`OutlineEditorView`): zoom stack + breadcrumb chrome ("⟵ zoom out" = full out, ancestor crumbs zoom to that node, "here" inert), double-click-any-bullet zooms in (the double-click's two clicks round-trip the fold toggle, net state unchanged), Esc stack = drag-cancel → selection-collapse → zoom-out-one; the 20pt left margin became the hover-revealed ⋮⋮ grip cell (fills the row height so its frame reads as row geometry), static rows carry a body catcher (click focuses, ⇧click extends the block selection, drag when the row is in the selection), drop indicators (2px rust seam line at the future bullet column, 2px ring for onto, dashed + muted when invalid), the moving run lifts to 0.3 opacity, and a successful drop selects the run (anchor = first, focus = last).
- **Drag plumbing** (`OutlineDrag.swift`): one transparent `CatcherView` NSView per row (`.grip` / `.body`) with a 4px click/drag threshold, then monitor-owned tracking — local monitor for dragged/up/Esc, global for dragged/up outside the app. No system dragging session: Esc-cancel can never resolve as a drop, and there is no destination dance. Live row geometry comes from a view-tree walk (`CatcherView.rowFrames(in:)`) reading CURRENT window-space frames on every pointer event — scroll-proof and SDK-proof.
- **`OutlineRowTextView.swift` split out** (the promoted row editor + `RowTextView`, unchanged code) to hold `OutlineEditorView.swift` under swiftlint's file/type length ceilings; the zoom+drag+structure handlers live in a same-file `extension OutlineEditorView` (private state stays file-scoped — the PostsModel posture).
- **Tests**: OutlineTreeTests gains the extract/insertRun pins; OutlinePresenterTests gains nine — dragged run dedup, validity rules, precise before/afterLast/lastChild landings (incl. the seam-below-a-deeper-follower nest and cross-parent moves), contiguous batch landing, origin no-ops, zoom projection/rebased depths/fold interplay/rangeIDs boundary, and the fat-gap band geometry (both coordinate orientations).
- **Test targets un-broken**: 8e70f69 bumped the app to `MACOSX_DEPLOYMENT_TARGET = 27.0` but left MuseionTests/UITests at 26.5 — tests could not even compile against the 27.0 module. All six configs now say 27.0 (a plain build-setting edit, the sanctioned pbxproj change).
## Decisions & Rationale
| Decision | Rationale |
|----------|-----------|
| Variant A fat gaps, exactly as calibrated | The P1 verdict (2026-10-16): complete position coverage via ONE insert rule + ONE nest rule — cheapest presenter math, most predictable at speed; drag is the secondary affordance in a keyboard-first app. |
| Monitor-owned drag instead of `NSDraggingSession` | A system session gives no way to distinguish Esc-cancel from drop-over-nothing (both end with operation `[]` and no destination accepted) — an Esc could apply a move. Hand-rolled local+global monitors own every transition; the global monitor supplies the mouse capture a session would give. |
| Geometry from an AppKit view-tree walk, not SwiftUI spaces | SwiftUI 27 removed `.window` from `CoordinateSpaceProtocol` (only `.local`/`.global`/`.named` remain); cached frames also go stale on scroll. The catchers ARE NSViews at the row positions, so a live walk reads current window frames every event — stable and always fresh. |
| Drop math on ids, anchor re-resolved after extraction | The applyBatch re-resolve discipline: indices shift while extracting, ids never do. Extraction runs in reverse document order so earlier paths stay valid without re-resolution. |
| No-op drops restore the snapshot | "Drop back at origin" must leave storage untouched (the guard contract): compare the result tree to the snapshot, restore + return false when equal. |
| Zoom roots at the node's CHILDREN, node's fold ignored | The prototype's projection (`walk(base.children, 0)`): the zoom root becomes the breadcrumb, its children are the document. |
| Esc order: drag → selection → zoom | The prototype's keydown order; the drag's own monitor is installed after the surface's Esc monitor, so it runs first (last-installed wins). |
| Same-file `extension OutlineEditorView` for handlers | swiftlint `type_body_length` (350); extensions are measured separately, private state stays visible in-file. The PostsModel posture, applied to a view. |
## Gotchas & Fixes
| Problem | Root Cause | Fix |
|---------|------------|-----|
| Random subsets of unrelated tests "failed (0.000 seconds)" across runs, `Crash: Museion at Runner._applyScopingTraits` | One test's `fatalError` (my `nodes[3]` on a 3-root parse) killed the shared Swift Testing runner process; everything in flight in that process reported failed | Fixed the index; parallel runs went green once nothing crashed |
| `compiling for macOS 26.5, but module 'Museion' has a minimum deployment target of macOS 27.0` | 8e70f69 bumped only the app target; MuseionTests/UITests still built for 26.5 | All six `MACOSX_DEPLOYMENT_TARGET` configs → 27.0 |
| `type 'CoordinateSpaceProtocol' has no member 'window'` | SwiftUI 27 dropped the `.window` space from the protocol | Geometry via the AppKit view-tree walk (see decisions) |
| hitTestDrop edge bands dead-ended (points 1–6pt above the first row returned nil) | Sign error: I read the prototype's `py < first.top + 6` as "more than 6pt beyond the edge" instead of "within/over the edge ±6" — and window coords are y-up, flipping both comparisons | Tolerance reaches INTO the edge row; orientation auto-detected from first/last frames; both orientations test-pinned |
| Seam indicator drew half a row LOW — through the middle of the block below the hovered gap (live dogfood, 2026-10-16) | `seamLine`'s `Color.clear` spacer was height-flexible: the HStack expanded to the full row height and vertically CENTERED the 2pt bar, so the row's `.frame(alignment: .top/.bottom)` had nothing to align | Pin the spacer's height to 2 — the HStack now stays 2pt tall and the frame alignment puts the line exactly on the row edge |
| `NSWindow has no member 'convert'` | The screen-point API is `convertPoint(fromScreen:)` in this SDK | Renamed |
| `nonisolated extension` needed for the presenter extension in OutlineDrag.swift | Default-MainActor project: extension members would be MainActor-isolated while tests call them synchronously | `nonisolated extension OutlinePresenter` (Swift 6.1+) |
## Files Changed
| File | Change Summary |
|------|---------------|
| `Museion/OutlineTree.swift` | `extract` + `insertRun` drag primitives, `withChildren` accessor |
| `Museion/OutlineEditorView.swift` | #112 surface: zoom stack + breadcrumb, grip cell, body catchers, drop indicators, lifted run, Esc stack, ⇧click extend; zoom-aware projection calls; handlers in a same-file extension |
| `Museion/OutlineDrag.swift` (new) | `OutlineDragCatcher`/`CatcherView` (grip + body), `DragTracker` monitors, presenter drop-math extension, `DragInfo`/`DropGeometry`/`HLine` |
| `Museion/OutlineRowTextView.swift` (new) | The promoted row editor + `RowTextView`, extracted unchanged from OutlineEditorView.swift |
| `Museion.xcodeproj/project.pbxproj` | Test/UITest deployment targets 26.5 → 27.0 (aligned with 8e70f69) |
| `MuseionTests/OutlineTreeTests.swift` | extract/insertRun pins |
| `MuseionTests/OutlinePresenterTests.swift` | Nine #112 pins: dedup, validity, landings, batches, no-ops, zoom, fat-gap geometry |
| `Museion/ProfileBackup.swift`, `Museion/ReadingPresenter.swift`, `Museion/ReadingSurface.swift`, `MuseionTests/ProfileBackupTests.swift`, `spike/*`, `prototypes/GateUIPrototype.swift` | SwiftFormat drift from the house `swiftformat .` pass (pre-existing formatting lag, no semantic change) |
## Open Items & Next Steps
- [ ] Map #110 continues: S4 Convert to Post (#114) and S5 prose-list shortcuts (#115) remain open on the frontier.
- [ ] Commit + push pending authorization (house rule: never commit autonomously). The slice spans the files above plus the devlog and DOX updates.
- [ ] Known ceilings (ponytail-marked in code): no auto-scroll mid-drag (edge timer is the upgrade path); no floating ghost chip (lifted rows + indicators carry the feedback — the prototype's ghost was calibration chrome); click-to-focus still lands the caret at the row end.
- [ ] Interaction-level feel (pointer drag, zoom chrome) was calibrated live at the P1 prototype and the math is unit-pinned, but the landed AppKit wiring has not been hand-driven in a running app yet — worth a minute of dogfooding before closing the map.
## Session audit (finish-audit pass)
Three fresh-context reviewers (ponytail / security / general) over the working-tree diff. Accepted and fixed, each behind a pin (`MuseionTests/OutlineDragTests.swift`, new):
- **Drag lifetime (Medium)** — `armDrag` closures held the catcher weakly; a mid-drag scroll could drop the origin row's catcher and strand the surface's `drag` state (lifted rows, stale chrome) at mouse-up. Window + callbacks are now captured strongly at arm time; pinned by a post-arm callback swap (the old code fails the pin — verified live).
- **Tracker stacking (Info)** — `DragTracker.current` finishes a never-ended predecessor as a cancel on the next arming; pinned.
- **rowFrames grip preference (Low)** — the full-row GRIP frame now wins over the body catcher's text-only frame regardless of subview visit order; pinned both orders.
- **hitTestDrop y-up only (lean)** — the y-down auto-detect was prototype carryover (both callers feed window geometry); deleted with its y-down test cases, seam-band assertions ported to y-up.
- **DropGeometry single source (lean)** — the guide-rail Canvas now reads `bulletCenter`/`railUnit` instead of hardcoded 18/11, so seam and rails cannot drift.
- **Catcher closure signatures (lean)** — `payload`/`onClick`/`onShiftClick` no longer echo `rowID` back; they capture the row.
Probes settled two harness disputes: local NSEvent monitors DO fire on `NSApp.sendEvent`, but only for events with a real window number (window-0 events never reach monitors — the Esc probe doc's "monitors can't run in the host" claim corrected); and once-installed NSViews keep AppKit-internal retains in the host (a dealloc-based pin is not reproducible — the callback-swap pin is the observable). Deferred explicitly: drag undo is its own slice (pre-existing pattern across all structural ops); per-event view-walk cost revisits with the auto-scroll timer (ponytail ceiling already marked); wf113 verdict wiring (post-drop selection, zoom reconcile, Esc order) covered by the planned dogfood pass. Rejected: the `nextEvent`-loop rewrite of DragTracker — unverifiable without interactive drag, and a lost mouse-up across an app switch would hang the loop where the global monitor degrades to a clean cancel. GitNexus: re-indexed; CatcherView impact = CRITICAL (57 dependents) — discharged by full build + full unit suite green + the three pins.
---
*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-16 | issue | [20261016-issue112-outline-interaction-ii_log.md](20261016-issue112-outline-interaction-ii_log.md) | S6 landed: drag-reorder + zoom in the outliner per wf113 verdict A; AppKit-tree hit-testing; tests un-broken for target 27.0 |
| 2026-10-15 | issue | [20261015-issue111-outline-guard_log.md](20261015-issue111-outline-guard_log.md) | #111 mixed-content outline guard: parsesWithLoss + open ask, audit round (reselect/displacement holes pinned) — 179 tests green |
| 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 |