From b0ab800d3d155c2eee703fea5a6c36a95ba6f45f Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Fri, 9 Oct 2026 11:11:36 +0200 Subject: [PATCH] =?UTF-8?q?feat(workspace):=20focus=20mode=20=E2=80=94=20r?= =?UTF-8?q?ecession,=20hover=20reveal,=20soft=20caret=20centering=20(#87)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Map #21 build child. Toggle via View menu / ⌘⇧F; panes and toolbar recede, overlay hover reveal (left: rail+library, right: mentor), soft caret centering while typing, loud save failure, ⌘S armed in focus. Full suite green; calibration gate #88 judges calm. --- AGENTS.md | 1 + Museion/AGENTS.md | 1 + Museion/DesignTokens.swift | 7 + Museion/FocusChrome.swift | 191 ++++++++++++++++++ Museion/MuseionApp.swift | 25 +++ Museion/PostEditorView.swift | 85 ++++++-- Museion/PostsPaneView.swift | 143 +++++++------ Museion/WorkspaceView.swift | 82 +++++--- MuseionTests/AGENTS.md | 1 + MuseionTests/FocusModeTests.swift | 64 ++++++ .../devlog/20261009-issue87-focus-mode_log.md | 47 +++++ docs/devlog/INDEX.md | 1 + 12 files changed, 550 insertions(+), 98 deletions(-) create mode 100644 Museion/FocusChrome.swift create mode 100644 MuseionTests/FocusModeTests.swift create mode 100644 docs/devlog/20261009-issue87-focus-mode_log.md diff --git a/AGENTS.md b/AGENTS.md index 78be1fd..3c26c6c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -177,6 +177,7 @@ Session logs live in `docs/devlog/` (one per completed task/issue/milestone). Fu | Date | Log | |------|-----| +| 2026-10-09 | [20261009-issue87-focus-mode_log.md](docs/devlog/20261009-issue87-focus-mode_log.md) | | 2026-10-08 | [20261008-issue84-view-menu-doubled_log.md](docs/devlog/20261008-issue84-view-menu-doubled_log.md) | | 2026-10-08 | [20261008-issue83-save-indicator-honesty_log.md](docs/devlog/20261008-issue83-save-indicator-honesty_log.md) | | 2026-10-08 | [20261008-issue77-editing-parity_log.md](docs/devlog/20261008-issue77-editing-parity_log.md) | diff --git a/Museion/AGENTS.md b/Museion/AGENTS.md index 54c7db6..564eeb3 100644 --- a/Museion/AGENTS.md +++ b/Museion/AGENTS.md @@ -28,6 +28,7 @@ Owned by the root AGENTS.md contract. The `.xcodeproj` uses **filesystem-synchro - `PostsModel.swift` — `PostsModel` (@MainActor @Observable, app-scoped via `AppGateState.posts`): posts list + selection + New Post draft (`PostDraft`, in-memory, no folder until first save); the open post's `EditorSession` (#19) — `select(_:home:)` ends the prior session with a flush and opens a new one, rename/trash of the open post drops the session, `shutdown()` flushes on app quit; recursive FSEvents stream (`kFSEventStreamCreateFlagFileEvents`, 0.5 s latency — the debounce; file-level so nested `post.md` edits fire) on `posts/`, rescan reusing `Post.scan` off-main (#61 — own ops route through the same rescan; the rescan also hands the session the open post's disk text — the #67 external-change check, watcher-echo suppressed by equality with the session's last-flushed text); `bind(home:)` from `.task(id: home)` creates `posts/` if missing + rebinds on repoint; lifecycle ops (`saveDraft`/`rename`/`trash`) set `lastError` on failure, never alert; the session's `onError` routes save failures into the same strip. - Editor core (#19 / S1.2, ADR-0010 mode B): `ProsePresenter.swift` (nonisolated) — **#77 reading-parity rework**: line-kind → attributes map mirroring the calm-ruled reading surface (#78) — leading calibrated to CSS `--lh 1.8` via font metrics (`lineHeightMultiple(font:cssLineHeight:)` — copying the CSS number would overshoot ~20%, TextKit multiplies the natural box), heading ladder h1 30 / h2 22 / h3 19 body-face-bold / h4+ bold body (blank source lines = 9pt half-height separators), quote = secondary ink + 20pt firstLineHeadIndent, fence interiors mono-14 on substrate (fence-state scan of the prefix for reattribute), inline traits: `**bold**` / `_italic_` / `` `code` `` / link labels (ink + underline; brackets+URL dim; CommonMark intraword-`_` never emphasizes), list markers + heading hashes + quote markers dim; full-doc `attribute` on load, per-paragraph `reattribute` on edit; plain store stays the source of truth (ADR-0010: presentation-only attributes). `EditorSession.swift` — @MainActor @Observable session per open post: `edit` re-arms a ~1 s debounce (#64) → `flush` (⌘S / selection change / window close / app quit also flush); `flush` writes `PostStore.overwrite` + the cursor sidecar, tracks `saveState` Changed→Saved (+ Save failed in accent, #65/#83, routed to `lastError` too — dirty = local text ≠ last flushed, shown honestly while the debounce holds); `diskDidChange(diskText:)` raises the #67 conflict when disk ≠ last-flushed AND ≠ local; `reloadFromDisk` (alert Yes) bumps `loadGeneration` + re-reads the sidecar; `keepLocal` (No/Esc) marks disk as seen — next autosave overwrites (explicit choice); the debounce never fires while the conflict alert is unanswered (#67 — only ⌘S is explicit enough to overwrite then); `teardown(flushFirst:)` is the owner's lifecycle exit (flush before rename's disk read, cancel-only on trash/vanish so the debounce can't fire at a dead path); `folderURL` exposes `posts//` for reading image resolution (#71). `PostEditorView.swift` — toolbar (mono crumb + `SaveStateDot`: 6px dot + label, accessibilityLabel role=status; drafts show "⌘S saves" instead — no Save button, the stub's died) + `ProseTextView` (NSViewRepresentable: plain `isRichText = false` NSTextView, presentation-only attributes, native undo/IME/find, 640pt measure, loads keyed by session `loadGeneration` — never per keystroke; cursor state pushed on selection change, restored clamped on load); window-close observer flushes (#64); the #67 alert (Reload / Keep Local) lives here, above the surface swap (shows while reading too). #77 spellcheck posture: `AppGateState.spellChecking` (default false — Neo triage, markdown on disk carries the spelling; per-launch, no persistence) toggled by Edit ▸ Check Spelling While Typing (`EditSpellingToggle` in MuseionApp.swift — commands views take `gate` as a plain property, they don't inherit the window environment) and applied to the live NSTextView in `makeNSView`/`updateNSView`. `PostStore` cursor sidecar (#66): `CursorState{selectionLocation,selectionLength,scrollOffset}` Codable in `posts//.museion-state.json` — Finder-invisible, dies with the folder on Trash, drafts skip it; content write and sidecar write are separate (a failed sidecar never reads as a failed save). - `SettingsPaneView.swift` — Home control (NSOpenPanel folder pick; files/canCreate on). Repoint-only semantics stated in-UI. #72 rework: the Typography/Text Flow sections are deleted — single-user app, prose type is hardcoded (ProseTypography constants + reading.css). +- Focus mode (#21 / S1.2, map #21; execution-carrying map — the build IS the prototype, the calibration gate judges calm): `AppGateState.isFocused` (transient like reading #68 — per-launch, no persistence; View ▸ Toggle Focus Mode beside Toggle Reading Mode + ⌘⇧F via `FocusModeToggle` in MuseionApp.swift; disabled when no post is open and no draft exists, but exit stays armed so trashing the open post can't trap). `FocusChrome.swift` — `HoverZone` (tracking-area edge strip, click-through via `hitTest → nil`), `FocusOverlayPanel` (slide-in overlay panel — floats over the measure, never pushes it; 140 ms hide grace covers the zone→panel transit), `CaretCentering` (soft caret centering: ±60pt comfort band, pure `targetOffset` math + animated clip-view scroll from `textDidChange` only — scrollback/drag-selection never fought, document clamp parks at the bottom, no jump). `WorkspaceView` hides the rail in focus (pane takes full width); left-edge hover slides rail+library back in (library only when window ≥1100px — #17's width collapse is not overridden). `PostsPaneView` hides library+mentor columns; right-edge hover slides the mentor back in. `PostsLibraryColumn` (extracted from PostsPaneView) is the shared library implementation, unfocused layout and focus overlay alike — rename sheet + context menu travel with it. `PostEditorView` — toolbar row recedes (unless save failed: the full SaveStateDot + "Save failed" widget reappears as a floating top overlay — failure stays loud); editor ground swaps surface → workspace background (`focusGround`); ⌘S moved to body level so it stays armed with the toolbar hidden (drafts have no autosave); `ProseTextView.focused` carries the ground + centering posture through the representable (NSColor twin `DesignTokens.workspaceBackground` — SwiftUI Color can't cross into NSTextView). Focus × reading orthogonal (⌘R works in focus, ⌘⇧F works while reading — independent state axes). - Reading mode (#76 / S1.2, map #20; ADR-0011 apex HTML pipeline; decisions #68/#69/#70/#73): `ReadingPresenter.swift` (nonisolated, pure) — `stampSource` prepends `` sentinels before every blank-line chunk (apex passes HTML comments through); `apexRender` runs the **bundled apex binary** (`Museion/Resources/apex`, fs-sync group ships it in Resources automatically; fallback chain bundle → `APEX_PATH` → Homebrew, dev-only) with `-t html --no-mixed-lists --embed-images [--base-dir ]` (no-mixed-lists REQUIRED: apex default merges ordered-after-bullets into one
    , killing `1. 1. 1.` renumbering; embed-images inlines base64 so `loadHTMLString` needs no file access and nothing is written to the vault); `stampHTML` regex-rewrites sentinels to `data-source-line="N"` on the following element (0 mis-stamps corpus-wide, #74); `blocks(for:)` builds the line↔UTF-16-range map (the #68 click→edit/scroll-sync contract); `page(for:postFolder:)` assembles the shell with `styleSheet()` — #72 rework: the whole stylesheet is `Museion/Resources/reading.css`, read FRESH per page build (dev builds prefer the repo copy via DerivedData-path detection, so CSS edits apply on the next reading toggle with no rebuild; the bundle copy ships in release). Values hardcoded for Alexander's fonts: Valkyrie OT B body 17/1.5, Concourse OT headings (w600), UbuntuMono code 14, 66ch measure — no UserDefaults, no Settings. **#72 polish (critique-directed, 2026-10-07):** flow defaults leading 1.5 / para 0.65 lines / code 14px; heading ladder h1 1.15× / h2 0.85× / h3 body×1.12 body-face w600 with cling margins (hN→content margin-top 0, hN+hN 0.35em, `body > :first-child` no offset); blockquote confident (near-ink #48484d, 3px rail #a1a1a6, nesting degrades to hairline); tables booktabs (top/bottom rules, heavier header rule, no vertical grid, full width); code = substrate-tint panel, inline code 0.88em relative; link underline #a1a1a6 → ink on hover; `::selection`/`:focus-visible` themed; secondary tokens `--secondary/--rule/--substrate`. Fallback on apex failure = escaped source in a `
    ` (#69 rule: fallback is the source, not a second renderer); footnotes render natively (apex upgrade over #69's fallback-decision). `ReadingSurface.swift` — `ReadingStateBox`/`CaretHintBox` (flow state, #68) + one **WKWebView reloaded in place** (remount was the dominant switch cost, #74; keyed render on generation+text+flowKey, never per keystroke): injected `probeJS` maps click→source line (tap = edit intent at that block), ⌘-click→`NSWorkspace.open`, scroll→top-visible-line into `stateBox.topSourceLocation`; `decidePolicyFor` allows only our own about:blank main-frame load, cancels the rest; entry-caret mapping scrolls the caret's block to top after `didFinish`; reload keyed on generation+text only (#72 rework: no flow knobs — the CSS file is read per build). DELETED with the pivot: `ReadingCanvasView`, `Decoration`, `framesForRange`, `ImagePopoverView` (ADR-0011: fallbacks rot; the #71 stale-flow defect dies unfixed). Editing side untouched: `ProsePresenter`, `EditorSession`, `ProseTextView`, toggle wiring (#68) all stand; editing-side spacing obligation lives in #77.
     - `AppGateState.museionHome` — app-scoped Home (UserDefaults `museionHome`, default `~/Documents/Museion` = `defaultMuseionHome`; non-file URLs read back as nil — the Home is always a folder). Explicit init: `Self` in a stored-property initializer breaks `@ObservationTracked` (covariant-Self error). 
     - `MentorPaneView` no longer carries a root min-frame — it lives in the 356pt mentor column.
    diff --git a/Museion/DesignTokens.swift b/Museion/DesignTokens.swift
    index 4c9daaa..0a16044 100644
    --- a/Museion/DesignTokens.swift
    +++ b/Museion/DesignTokens.swift
    @@ -19,6 +19,13 @@ enum DesignTokens {
     
     	static let radius: CGFloat = 10
     
    +	/// #21: NSColor twin of `background` — the focus-mode editor ground
    +	/// (NSColor can't be derived from SwiftUI Color at runtime).
    +	/// ponytail: nonisolated(unsafe) — NSColor isn't Sendable; never mutated.
    +	nonisolated(unsafe) static let workspaceBackground = NSColor(
    +		red: 0xFA / 255, green: 0xFA / 255, blue: 0xF7 / 255, alpha: 1,
    +	)
    +
     	/// The workspace grid: rail | posts library | editor | mentor (grid-template-columns
     	/// `56px 232px minmax(420px, 1fr) 356px`). Editor min (420) has no enforcement
     	/// yet — the editor column arrives with #19.
    diff --git a/Museion/FocusChrome.swift b/Museion/FocusChrome.swift
    new file mode 100644
    index 0000000..ee403fa
    --- /dev/null
    +++ b/Museion/FocusChrome.swift
    @@ -0,0 +1,191 @@
    +//
    +//  FocusChrome.swift
    +//  Museion
    +//
    +//  #21 (map #21): focus-mode machinery — the edge hover sensor, the overlay
    +//  panel that reveals recessed panes (rail+library left, mentor right), and
    +//  the soft caret centering. Panes NEVER push the measure: revealed panels
    +//  float above the surface and slide off when hover ends. Animation feel is
    +//  the fog's "slide curve" knob — calibrate here if not-calm.
    +//
    +
    +import AppKit
    +import SwiftUI
    +
    +// MARK: - Edge hover sensor
    +
    +/// Edge hover sensor: a tracking-area strip down one window edge that reports
    +/// pointer enter/leave and is transparent to clicks (`hitTest → nil`) — hover
    +/// must never steal a click from the text underneath.
    +struct HoverZone: NSViewRepresentable {
    +	enum Edge { case leading, trailing }
    +
    +	var edge: Edge
    +	var width: CGFloat
    +	var onHover: @MainActor (Bool) -> Void
    +
    +	final class SensorView: NSView {
    +		var edge: Edge = .leading
    +		var zoneWidth: CGFloat = 14
    +		var onHover: ((Bool) -> Void)?
    +
    +		private var trackingArea: NSTrackingArea?
    +
    +		override func updateTrackingAreas() {
    +			super.updateTrackingAreas()
    +			if let trackingArea {
    +				removeTrackingArea(trackingArea)
    +			}
    +			let stripX = edge == .leading ? 0 : max(0, bounds.width - zoneWidth)
    +			let area = NSTrackingArea(
    +				rect: NSRect(x: stripX, y: 0, width: min(zoneWidth, bounds.width), height: bounds.height),
    +				options: [.mouseEnteredAndExited, .activeInActiveApp],
    +				owner: self,
    +				userInfo: nil,
    +			)
    +			addTrackingArea(area)
    +			trackingArea = area
    +		}
    +
    +		override func mouseEntered(with _: NSEvent) {
    +			onHover?(true)
    +		}
    +
    +		override func mouseExited(with _: NSEvent) {
    +			onHover?(false)
    +		}
    +
    +		/// Click-through: a sensor, not a surface.
    +		override func hitTest(_: NSPoint) -> NSView? {
    +			nil
    +		}
    +	}
    +
    +	func makeNSView(context _: Context) -> SensorView {
    +		let view = SensorView()
    +		configure(view)
    +		return view
    +	}
    +
    +	func updateNSView(_ view: SensorView, context _: Context) {
    +		configure(view)
    +	}
    +
    +	private func configure(_ view: SensorView) {
    +		view.edge = edge
    +		view.zoneWidth = width
    +		view.onHover = onHover
    +		view.updateTrackingAreas()
    +	}
    +}
    +
    +// MARK: - Overlay panel
    +
    +/// A recessed pane revealed by edge hover: the sensor strip runs down the
    +/// window edge; the panel slides in from that edge, floating OVER the measure
    +/// (never pushing it), and slides out after a short grace when hover ends —
    +/// the grace covers the pointer's transit from zone to panel.
    +struct FocusOverlayPanel: View {
    +	let edge: HoverZone.Edge
    +	let panelWidth: CGFloat
    +	@ViewBuilder var content: () -> Content
    +
    +	@State private var revealed = false
    +	@State private var hideTask: Task?
    +
    +	private let revealAnimation = Animation.easeOut(duration: 0.2)
    +	private let hideAnimation = Animation.easeIn(duration: 0.15)
    +	/// Grace covering the pointer's transit from the edge zone onto the panel.
    +	private let transitGrace: Duration = .milliseconds(140)
    +
    +	var body: some View {
    +		ZStack(alignment: edge == .leading ? .leading : .trailing) {
    +			HoverZone(edge: edge, width: 14) { hover($0) }
    +				.frame(maxWidth: .infinity, maxHeight: .infinity)
    +			content()
    +				.background(DesignTokens.surface)
    +				.shadow(color: .black.opacity(0.10), radius: 12, y: 0)
    +				.frame(maxHeight: .infinity)
    +				.allowsHitTesting(revealed)
    +				.onHover { hover($0) }
    +				.opacity(revealed ? 1 : 0)
    +				.offset(x: revealed ? 0 : hiddenOffset)
    +		}
    +	}
    +
    +	/// Park just past the edge while hidden (8pt of clearance so the shadow
    +	/// doesn't bleed in).
    +	private var hiddenOffset: CGFloat {
    +		edge == .leading ? -panelWidth - 8 : panelWidth + 8
    +	}
    +
    +	private func hover(_ inside: Bool) {
    +		hideTask?.cancel()
    +		if inside {
    +			if !revealed {
    +				withAnimation(revealAnimation) { revealed = true }
    +			}
    +		} else {
    +			hideTask = Task {
    +				try? await Task.sleep(for: transitGrace)
    +				guard !Task.isCancelled else { return }
    +				withAnimation(hideAnimation) { revealed = false }
    +			}
    +		}
    +	}
    +}
    +
    +// MARK: - Soft caret centering (#21)
    +
    +/// Soft caret centering (the Neo input, softened): keep the caret inside a
    +/// comfort band around the visible center WHILE TYPING — `centerCaretWhileTyping`
    +/// is called from `textDidChange` only, so scrollback and drag-selection never
    +/// get fought. No jump at the document bottom: the clamp parks the scroll at
    +/// the document edge and follows line by line as the document grows.
    +nonisolated enum CaretCentering {
    +	/// Comfort band half-height (pt) around the visible center.
    +	static let band: CGFloat = 60
    +
    +	/// The visible-origin Y that parks the caret back at the center, or nil
    +	/// when it already sits inside the band (or the document clamp leaves the
    +	/// origin where it is — e.g. typing at the very end of a short document).
    +	/// Pure math — pinned by FocusModeTests.
    +	static func targetOffset(
    +		caretY: CGFloat,
    +		visibleMinY: CGFloat,
    +		visibleHeight: CGFloat,
    +		documentHeight: CGFloat,
    +	) -> CGFloat? {
    +		let center = visibleMinY + visibleHeight / 2
    +		guard abs(caretY - center) > band else { return nil }
    +		let raw = caretY - visibleHeight / 2
    +		let clamped = min(max(0, raw), max(0, documentHeight - visibleHeight))
    +		guard abs(clamped - visibleMinY) > 0.5 else { return nil }
    +		return clamped
    +	}
    +
    +	/// Applied: animate the scroll so the caret settles back toward the
    +	/// center. Typing only — never route scroll or selection events here.
    +	@MainActor
    +	static func centerCaretWhileTyping(textView: NSTextView) {
    +		guard let window = textView.window else { return }
    +		let sel = textView.selectedRange()
    +		guard sel.length == 0, sel.location >= 0 else { return }
    +		// firstRect(forCharacterRange:) answers in SCREEN coordinates.
    +		let screenRect = textView.firstRect(forCharacterRange: sel, actualRange: nil)
    +		let caret = textView.convert(window.convertFromScreen(screenRect), from: nil)
    +		guard let clip = textView.enclosingScrollView?.contentView else { return }
    +		let visible = textView.visibleRect
    +		guard let target = targetOffset(
    +			caretY: caret.midY,
    +			visibleMinY: visible.minY,
    +			visibleHeight: visible.height,
    +			documentHeight: textView.bounds.height,
    +		) else { return }
    +		NSAnimationContext.runAnimationGroup { ctx in
    +			ctx.duration = 0.18
    +			ctx.allowsImplicitAnimation = true
    +			clip.animator().setBoundsOrigin(NSPoint(x: visible.minX, y: target))
    +		}
    +	}
    +}
    diff --git a/Museion/MuseionApp.swift b/Museion/MuseionApp.swift
    index fc251ba..84dcc38 100644
    --- a/Museion/MuseionApp.swift
    +++ b/Museion/MuseionApp.swift
    @@ -28,6 +28,11 @@ final class AppGateState {
     	/// asked via Edit ▸ Check Spelling While Typing. Per-launch only, no
     	/// persistence; markdown on disk already carries the spelling.
     	var spellChecking = false
    +	/// #21 (map #21): focus mode — transient like reading (#68), per-launch
    +	/// only, no persistence; a fresh open lands unfocused. Recesses the
    +	/// rail/library/mentor and the editor toolbar; overlay panes return on
    +	/// edge hover.
    +	var isFocused = false
     	/// #17: the Museion Home — repoint-only (ADR-0004). Defaults to
     	/// `~/Documents/Museion`; UserDefaults is the persistence floor: a Home is
     	/// a plain folder, nothing app-owned to put in a database. Non-file URLs
    @@ -90,6 +95,10 @@ struct MuseionApp: App {
     					NotificationCenter.default.post(name: .toggleReadingMode, object: nil)
     				}
     				.keyboardShortcut("r", modifiers: .command)
    +				// #21: focus mode — beside reading, same posture (system View
    +				// menu + shortcut). Transient like reading: no persistence, no
    +				// Esc exit (rejected at charting) — the toggle is the only way.
    +				FocusModeToggle(gate: gate)
     			}
     			// #50: reveal the snapshots folder in Finder (restore = manual
     			// copy-back, documented in the bundled help doc).
    @@ -123,6 +132,22 @@ private struct EditSpellingToggle: View {
     	}
     }
     
    +/// #21: the focus-mode toggle — plain property (commands views don't inherit
    +/// the window environment; observation tracking still invalidates the item).
    +/// Disabled with nothing open (no session, no draft) — a no-op guard.
    +private struct FocusModeToggle: View {
    +	let gate: AppGateState
    +
    +	var body: some View {
    +		// Entry guard: nothing open = nothing to focus on. Exit stays armed
    +		// even then (trashing the open post while focused must not trap).
    +		let canFocus = gate.isFocused || gate.posts.session != nil || gate.posts.draft != nil
    +		Button("Toggle Focus Mode") { gate.isFocused.toggle() }
    +			.keyboardShortcut("f", modifiers: [.command, .shift])
    +			.disabled(!canFocus)
    +	}
    +}
    +
     /// #50: reveals `~/Library/Application Support/Museion/Backups` in Finder —
     /// restore is manual Finder copy-back in v1 (help doc describes it).
     private struct OpenBackupFolderButton: View {
    diff --git a/Museion/PostEditorView.swift b/Museion/PostEditorView.swift
    index ca72102..825a2fe 100644
    --- a/Museion/PostEditorView.swift
    +++ b/Museion/PostEditorView.swift
    @@ -52,8 +52,10 @@ struct PostEditorView: View {
     
     	var body: some View {
     		VStack(spacing: 0) {
    -			toolbar
    -			Rectangle().fill(DesignTokens.border).frame(height: 1)
    +			if showsToolbar {
    +				toolbar
    +				Rectangle().fill(DesignTokens.border).frame(height: 1)
    +			}
     			if reading {
     				ReadingSurface(
     					text: renderText,
    @@ -73,7 +75,38 @@ struct PostEditorView: View {
     			}
     		}
     		.frame(maxWidth: .infinity, maxHeight: .infinity)
    -		.background(DesignTokens.surface)
    +		.background(focusGround)
    +		// #21: ⌘S stays armed in focus too — drafts have no autosave; the
    +		// trigger is invisible either way, so it lives here, not in the
    +		// receding toolbar.
    +		.background {
    +			Button("") { saveNow() }
    +				.keyboardShortcut("s", modifiers: .command)
    +				.opacity(0)
    +				.frame(width: 1, height: 1)
    +				.accessibilityHidden(true)
    +		}
    +		// #21: save failure is LOUD in focus — the full unfocused widget
    +		// (dot + "Save failed") reappears, floating at the top edge where
    +		// the toolbar row stood. Autosave keeps running underneath.
    +		.overlay(alignment: .top) {
    +			if gate.isFocused, session?.saveState == .failed {
    +				HStack(spacing: 7) {
    +					Circle()
    +						.fill(DesignTokens.accent)
    +						.frame(width: 6, height: 6)
    +					Text("Save failed")
    +				}
    +				.font(.system(size: 12))
    +				.foregroundStyle(DesignTokens.accent)
    +				.padding(.horizontal, 14)
    +				.padding(.vertical, 7)
    +				.background(DesignTokens.surface.opacity(0.96), in: RoundedRectangle(cornerRadius: DesignTokens.radius))
    +				.accessibilityElement(children: .ignore)
    +				.accessibilityLabel("Save state: Save failed")
    +				.transition(.move(edge: .top).combined(with: .opacity))
    +			}
    +		}
     		.onAppear {
     			if draftMirror.isEmpty {
     				draftMirror = draftText ?? ""
    @@ -102,6 +135,17 @@ struct PostEditorView: View {
     		}
     	}
     
    +	/// #21: the toolbar row recedes in focus (unless failure is loud).
    +	private var showsToolbar: Bool {
    +		!gate.isFocused || session?.saveState == .failed
    +	}
    +
    +	/// #21: focus runs on the workspace background, not the surface card —
    +	/// the centered measure on the workspace ground is all that remains.
    +	private var focusGround: Color {
    +		gate.isFocused ? DesignTokens.background : DesignTokens.surface
    +	}
    +
     	/// The text reading renders: live session text or the draft mirror.
     	private var renderText: String {
     		session?.text ?? draftMirror
    @@ -110,9 +154,9 @@ struct PostEditorView: View {
     	@ViewBuilder
     	private var editingSurface: some View {
     		if let session {
    -			ProseTextView(session: session, spellChecking: gate.spellChecking, caretHint: flipBackCaret)
    +			ProseTextView(session: session, spellChecking: gate.spellChecking, focused: gate.isFocused, caretHint: flipBackCaret)
     		} else {
    -			ProseTextView(draft: draftMirror, spellChecking: gate.spellChecking, onEdit: { newText in
    +			ProseTextView(draft: draftMirror, spellChecking: gate.spellChecking, focused: gate.isFocused, onEdit: { newText in
     				draftMirror = newText
     				draftEdited?(newText)
     			}, caretHint: flipBackCaret)
    @@ -175,12 +219,6 @@ struct PostEditorView: View {
     					.font(.system(size: 11, design: DesignTokens.mono))
     					.foregroundStyle(DesignTokens.muted)
     			}
    -			// #64: ⌘S stays immediate in both modes — invisible trigger.
    -			Button("") { saveNow() }
    -				.keyboardShortcut("s", modifiers: .command)
    -				.opacity(0)
    -				.frame(width: 1, height: 1)
    -				.accessibilityHidden(true)
     		}
     		.padding(.horizontal, 16)
     		.frame(minHeight: 40)
    @@ -242,26 +280,32 @@ struct ProseTextView: NSViewRepresentable {
     	var draft: String?
     	var onEdit: ((String) -> Void)?
     	var spellChecking = false
    +	/// #21: focus mode — the text ground joins the workspace background.
    +	var focused = false
     	var caretHint: (location: Int, token: Int)?
     
     	init(
     		session: EditorSession,
     		spellChecking: Bool = false,
    +		focused: Bool = false,
     		caretHint: (location: Int, token: Int)? = nil,
     	) {
     		self.session = session
     		self.spellChecking = spellChecking
    +		self.focused = focused
     		self.caretHint = caretHint
     	}
     
     	init(
     		draft: String,
     		spellChecking: Bool = false,
    +		focused: Bool = false,
     		onEdit: @escaping (String) -> Void,
     		caretHint: (location: Int, token: Int)? = nil,
     	) {
     		self.draft = draft
     		self.spellChecking = spellChecking
    +		self.focused = focused
     		self.onEdit = onEdit
     		self.caretHint = caretHint
     	}
    @@ -287,7 +331,9 @@ struct ProseTextView: NSViewRepresentable {
     		// #77: squiggles follow the posture toggle (default off).
     		tv.isContinuousSpellCheckingEnabled = spellChecking
     		tv.usesFindBar = true
    -		tv.backgroundColor = NSColor.white
    +		// #21: focus ground joins the workspace background; drawsBackground
    +		// stays true either way (white in the unfocused card).
    +		tv.backgroundColor = focused ? DesignTokens.workspaceBackground : NSColor.white
     		tv.typingAttributes = ProseTypography.bodyAttributes
     		tv.delegate = context.coordinator
     		tv.layoutManager?.allowsNonContiguousLayout = true
    @@ -310,7 +356,7 @@ struct ProseTextView: NSViewRepresentable {
     		// out at rest (iOS-like), instead of always occupying the right edge.
     		scroll.scrollerStyle = .overlay
     		scroll.drawsBackground = true
    -		scroll.backgroundColor = NSColor.white
    +		scroll.backgroundColor = focused ? DesignTokens.workspaceBackground : NSColor.white
     		context.coordinator.textView = tv
     		context.coordinator.sessionRef = session // strong: both die with the editor
     		return scroll
    @@ -320,6 +366,11 @@ struct ProseTextView: NSViewRepresentable {
     		guard let tv = scroll.documentView as? NSTextView else { return }
     		// #77: posture toggle while editing — cheap idempotent set.
     		tv.isContinuousSpellCheckingEnabled = spellChecking
    +		// #21: the ground follows focus in/out without a remount.
    +		let ground = focused ? DesignTokens.workspaceBackground : NSColor.white
    +		tv.backgroundColor = ground
    +		scroll.backgroundColor = ground
    +		context.coordinator.focused = focused
     		if let session {
     			context.coordinator.sessionRef = session
     			// Load only when the generation moved (open, Yes-reload) — never
    @@ -383,6 +434,9 @@ struct ProseTextView: NSViewRepresentable {
     		var sessionRef: EditorSession?
     		var loadedGeneration = -1
     		var appliedCaretToken = -1
    +		/// #21: focus posture mirror — soft centering applies while typing
    +		/// in focus only.
    +		var focused = false
     		/// #77: fence delimiter count — the cross-paragraph fence state
     		/// fingerprint. A moved count means a ``` was typed/deleted and every
     		/// line until the matching delimiter changed kind.
    @@ -409,6 +463,11 @@ struct ProseTextView: NSViewRepresentable {
     				tv.setSelectedRange(selected)
     			}
     			tv.typingAttributes = ProseTypography.bodyAttributes
    +			// #21: soft caret centering — typing only, never scrollback or
    +			// drag-selection (the reader never gets fought).
    +			if focused {
    +				CaretCentering.centerCaretWhileTyping(textView: tv)
    +			}
     			if let sessionRef {
     				sessionRef.edit(storage.string)
     			} else {
    diff --git a/Museion/PostsPaneView.swift b/Museion/PostsPaneView.swift
    index 948832e..342e80e 100644
    --- a/Museion/PostsPaneView.swift
    +++ b/Museion/PostsPaneView.swift
    @@ -22,7 +22,7 @@ struct PostsPaneView: View {
     	/// Width budget after the rail — drives column collapse (export media queries:
     	/// library hides ≤1100, mentor hides ≤920).
     	var availableWidth: CGFloat
    -	@State private var renamingPost: Post?
    +	@Environment(AppGateState.self) private var gate
     
     	private var showsLibrary: Bool {
     		availableWidth >= 1100 - DesignTokens.railWidth
    @@ -33,26 +33,35 @@ struct PostsPaneView: View {
     	}
     
     	var body: some View {
    -		HStack(spacing: 0) {
    -			if showsLibrary {
    -				libraryColumn
    -				paneBorder
    -			}
    -			editorColumn
    -			if showsMentor {
    -				paneBorder
    -				mentorColumn
    +		Group {
    +			if gate.isFocused {
    +				// #21: columns recede; the editor surface + centered measure on
    +				// the workspace background is all that remains. The mentor
    +				// returns by right-edge hover (overlay below).
    +				ZStack(alignment: .trailing) {
    +					editorColumn
    +					FocusOverlayPanel(edge: .trailing, panelWidth: DesignTokens.mentorWidth) {
    +						mentorColumn
    +					}
    +				}
    +			} else {
    +				HStack(spacing: 0) {
    +					if showsLibrary {
    +						PostsLibraryColumn(home: home, model: model)
    +						paneBorder
    +					}
    +					editorColumn
    +					if showsMentor {
    +						paneBorder
    +						mentorColumn
    +					}
    +				}
     			}
     		}
     		.task(id: home) {
     			// Bind: initial off-main scan + (re)start the FSEvents watcher (#61).
     			model.bind(home: home)
     		}
    -		.sheet(item: $renamingPost) { post in
    -			RenamePostSheet(post: post) { title in
    -				model.rename(post, to: title, home: home)
    -			}
    -		}
     	}
     
     	private var paneBorder: some View {
    @@ -61,9 +70,60 @@ struct PostsPaneView: View {
     			.frame(width: 1)
     	}
     
    -	// MARK: Library column
    +	// MARK: Editor column (#19: TextKit2 editor core)
     
    -	private var libraryColumn: some View {
    +	private var editorColumn: some View {
    +		VStack(spacing: 0) {
    +			if let draft = model.draft {
    +				PostEditorView(
    +					session: nil,
    +					draftText: draft.text,
    +					draftEdited: { model.updateDraft($0) },
    +					draftSave: {
    +						model.saveDraft(home: home)
    +					},
    +				)
    +				.id("draft")
    +			} else if let session = model.session, session.postID == model.selectedPostID {
    +				PostEditorView(session: session, draftText: nil)
    +					.id(session.postID)
    +			} else {
    +				VStack(spacing: 10) {
    +					Image(systemName: "square.and.pencil")
    +						.font(.largeTitle)
    +						.foregroundStyle(DesignTokens.muted)
    +					Text("Select a post, or start a new one.")
    +						.font(.callout)
    +						.foregroundStyle(DesignTokens.muted)
    +				}
    +				.frame(maxWidth: .infinity, maxHeight: .infinity)
    +			}
    +			if let error = model.lastError {
    +				Text(error)
    +					.font(.system(size: 11, design: DesignTokens.mono))
    +					.foregroundStyle(DesignTokens.accent)
    +					.padding(.vertical, 6)
    +			}
    +		}
    +		.frame(maxWidth: .infinity, maxHeight: .infinity)
    +		.background(DesignTokens.surface)
    +	}
    +
    +	private var mentorColumn: some View {
    +		MentorPaneView(model: mentor, binaryPath: mentorBinaryPath)
    +			.frame(width: DesignTokens.mentorWidth)
    +	}
    +}
    +
    +/// #21: the library column, shared by the unfocused layout and the focus-mode
    +/// left reveal overlay — one implementation, both surfaces. Owns the rename
    +/// sheet + context menu (they travel with the post rows).
    +struct PostsLibraryColumn: View {
    +	let home: URL
    +	var model: PostsModel
    +	@State private var renamingPost: Post?
    +
    +	var body: some View {
     		VStack(spacing: 0) {
     			PaneHeader(title: "Posts") {
     				Button {
    @@ -110,6 +170,11 @@ struct PostsPaneView: View {
     			}
     		}
     		.frame(width: DesignTokens.libraryWidth)
    +		.sheet(item: $renamingPost) { post in
    +			RenamePostSheet(post: post) { title in
    +				model.rename(post, to: title, home: home)
    +			}
    +		}
     	}
     
     	private var emptyState: some View {
    @@ -124,50 +189,6 @@ struct PostsPaneView: View {
     		.padding(38)
     		.frame(maxWidth: .infinity, maxHeight: .infinity)
     	}
    -
    -	// MARK: Editor column (#19: TextKit2 editor core)
    -
    -	private var editorColumn: some View {
    -		VStack(spacing: 0) {
    -			if let draft = model.draft {
    -				PostEditorView(
    -					session: nil,
    -					draftText: draft.text,
    -					draftEdited: { model.updateDraft($0) },
    -					draftSave: {
    -						model.saveDraft(home: home)
    -					},
    -				)
    -				.id("draft")
    -			} else if let session = model.session, session.postID == model.selectedPostID {
    -				PostEditorView(session: session, draftText: nil)
    -					.id(session.postID)
    -			} else {
    -				VStack(spacing: 10) {
    -					Image(systemName: "square.and.pencil")
    -						.font(.largeTitle)
    -						.foregroundStyle(DesignTokens.muted)
    -					Text("Select a post, or start a new one.")
    -						.font(.callout)
    -						.foregroundStyle(DesignTokens.muted)
    -				}
    -				.frame(maxWidth: .infinity, maxHeight: .infinity)
    -			}
    -			if let error = model.lastError {
    -				Text(error)
    -					.font(.system(size: 11, design: DesignTokens.mono))
    -					.foregroundStyle(DesignTokens.accent)
    -					.padding(.vertical, 6)
    -			}
    -		}
    -		.frame(maxWidth: .infinity, maxHeight: .infinity)
    -		.background(DesignTokens.surface)
    -	}
    -
    -	private var mentorColumn: some View {
    -		MentorPaneView(model: mentor, binaryPath: mentorBinaryPath)
    -			.frame(width: DesignTokens.mentorWidth)
    -	}
     }
     
     /// #60: Explicit Rename dialog — asks the new Title (not a slug).
    diff --git a/Museion/WorkspaceView.swift b/Museion/WorkspaceView.swift
    index aa1c67a..bc95cf7 100644
    --- a/Museion/WorkspaceView.swift
    +++ b/Museion/WorkspaceView.swift
    @@ -24,30 +24,34 @@ struct WorkspaceView: View {
     	}
     
     	var body: some View {
    -		@Bindable var gate = gate
    -
    -		return GeometryReader { geo in
    -			HStack(spacing: 0) {
    -				navRail
    -				paneBorder
    -				switch selection {
    -				case .posts:
    -					// #14: mentor column hands in the app-scoped model + gate's winner.
    -					// Column collapse mirrors the export's media queries (library ≤1100,
    -					// mentor ≤920) as macOS pane collapse per the PRD.
    -					PostsPaneView(
    -						home: gate.museionHome,
    -						mentor: gate.mentor,
    -						mentorBinaryPath: gate.gateModel.currentBinaryPath,
    -						model: gate.posts,
    -						availableWidth: geo.size.width - DesignTokens.railWidth,
    -					)
    -				case .sessions:
    -					PlaceholderPane(title: "Sessions", detail: "Session lifecycle arrives with S2.3 (#28).")
    -				case .learnings:
    -					PlaceholderPane(title: "Learnings", detail: "Promote, consult, and decay arrive with S4 (#26, #27).")
    -				case .settings:
    -					SettingsPaneView(home: $gate.museionHome)
    +		GeometryReader { geo in
    +			Group {
    +				if gate.isFocused {
    +					// #21: the rail recedes; the pane takes the full width. The
    +					// measure stays centered — revealed panes float, never push.
    +					paneContent(geo)
    +				} else {
    +					HStack(spacing: 0) {
    +						navRail
    +						paneBorder
    +						paneContent(geo)
    +					}
    +				}
    +			}
    +			// #21: left-edge hover slides rail+library back in as an overlay.
    +			// Library only while the window width allows it (#17 verdict stands:
    +			// a collapsed pane is not summoned by focus).
    +			.overlay {
    +				if gate.isFocused {
    +					FocusOverlayPanel(edge: .leading, panelWidth: leftRevealWidth(geo)) {
    +						HStack(spacing: 0) {
    +							navRail
    +							paneBorder
    +							if geo.size.width >= 1100 {
    +								PostsLibraryColumn(home: gate.museionHome, model: gate.posts)
    +							}
    +						}
    +					}
     				}
     			}
     			.background(DesignTokens.background)
    @@ -56,6 +60,36 @@ struct WorkspaceView: View {
     		.frame(minWidth: 480, minHeight: 320)
     	}
     
    +	@ViewBuilder
    +	private func paneContent(_ geo: GeometryProxy) -> some View {
    +		@Bindable var gate = gate
    +		switch selection {
    +		case .posts:
    +			// #14: mentor column hands in the app-scoped model + gate's winner.
    +			// Column collapse mirrors the export's media queries (library ≤1100,
    +			// mentor ≤920) as macOS pane collapse per the PRD.
    +			PostsPaneView(
    +				home: gate.museionHome,
    +				mentor: gate.mentor,
    +				mentorBinaryPath: gate.gateModel.currentBinaryPath,
    +				model: gate.posts,
    +				availableWidth: geo.size.width - DesignTokens.railWidth,
    +			)
    +		case .sessions:
    +			PlaceholderPane(title: "Sessions", detail: "Session lifecycle arrives with S2.3 (#28).")
    +		case .learnings:
    +			PlaceholderPane(title: "Learnings", detail: "Promote, consult, and decay arrive with S4 (#26, #27).")
    +		case .settings:
    +			SettingsPaneView(home: $gate.museionHome)
    +		}
    +	}
    +
    +	/// The left reveal panel's width: rail + border (+ library when the window
    +	/// width still grants it — the unfocused verdict, not the focused budget).
    +	private func leftRevealWidth(_ geo: GeometryProxy) -> CGFloat {
    +		DesignTokens.railWidth + 1 + (geo.size.width >= 1100 ? DesignTokens.libraryWidth : 0)
    +	}
    +
     	/// 1px contract border between rail and pane (`.rail { border-right }`).
     	private var paneBorder: some View {
     		Rectangle()
    diff --git a/MuseionTests/AGENTS.md b/MuseionTests/AGENTS.md
    index e4d9ba8..db7a92a 100644
    --- a/MuseionTests/AGENTS.md
    +++ b/MuseionTests/AGENTS.md
    @@ -25,6 +25,7 @@ Owned by the root AGENTS.md contract.
     - `EditorSessionTests.swift` (#19) — session mechanics via `makeSessionHome`/`seedPost`: debounce → flush + sidecar round-trip, clean-flush no-op + ⌘S immediate, #67 conflict (echo suppressed, Yes-reload, No-keep-local → overwrite), write failure → `.failed` + retry.
     - `ReadingPresenterTests.swift` (#76, ADR-0011) — apex HTML pipeline coverage with inline fixture strings: chunker sentinel stamping, stamper attribute rewrite (multi-digit), `blocks(for:)` line↔range map (monotonic, 1-based lines, exact chunk offsets — the click→edit map), pipeline tests running the REAL bundled apex binary (headings/inline marks, `1. 1. 1.` renumber via native `
      `, mixed-lists stay split, table/quote/fence/link/HR constructs with exact `data-source-line` stamps, base64 image embed against `spike/prose`, native footnotes), fallback = escaped source, stylesheet carries the slot CSS vars. - `ProsePresenterTests.swift` (#77) — editing-surface parity pinned: heading ladder sizes (30/22/19/17-bold), half-height blanks (9pt), quote secondary-ink + indent, fence interior mono-14, inline traits (bold/italic/code/link underline + dimmed marks), CSS-1.8 leading calibration tolerance, CommonMark intraword-underscore rule, reattribute with fence-state retrofit. +- `FocusModeTests.swift` (#21, map #21) — soft-centering band math pinned: in-band no-op, below-band recenter down, above-band recenter up, document-bottom clamp (parks, then no-ops while parked — no jump), short-document floor at 0. ## Verification diff --git a/MuseionTests/FocusModeTests.swift b/MuseionTests/FocusModeTests.swift new file mode 100644 index 0000000..443c48e --- /dev/null +++ b/MuseionTests/FocusModeTests.swift @@ -0,0 +1,64 @@ +// +// FocusModeTests.swift +// Museion +// +// #21 (map #21): the soft-centering band math — the one piece of focus +// logic pure enough to pin. In-band stays put, out-of-band recenters, +// document clamp parks at the bottom (no jump), already-clamped no-ops. +// + +import CoreFoundation +@testable import Museion +import Testing + +struct FocusModeTests { + /// A tall viewport: 800pt visible, 4000pt document. + @Test func `caret inside band leaves scroll alone`() { + let center = 400.0 // visibleMinY 0 + 800/2 + #expect(CaretCentering.targetOffset( + caretY: center, visibleMinY: 0, visibleHeight: 800, documentHeight: 4000, + ) == nil) + #expect(CaretCentering.targetOffset( + caretY: center + CaretCentering.band - 1, visibleMinY: 0, visibleHeight: 800, documentHeight: 4000, + ) == nil) + } + + @Test func `caret below band recenters down`() throws { + let target = CaretCentering.targetOffset( + caretY: 900, visibleMinY: 0, visibleHeight: 800, documentHeight: 4000, + ) + #expect(target != nil) + #expect(try abs(#require(target) - 500) < 0.5) // 900 - 800/2 + } + + @Test func `caret above band recenters up`() throws { + // Scrolled deep (visibleMinY 2000), caret back at 1800. + let target = CaretCentering.targetOffset( + caretY: 1800, visibleMinY: 2000, visibleHeight: 800, documentHeight: 4000, + ) + #expect(target != nil) + #expect(try abs(#require(target) - 1400) < 0.5) // 1800 - 800/2 + } + + @Test func `document bottom clamps no jump`() throws { + // Typing at the very end of a short-ish document: the raw target + // (2600) would over-scroll past the last line; the clamp parks at + // documentHeight - visibleHeight and FOLLOWS line by line. + let target = CaretCentering.targetOffset( + caretY: 3000, visibleMinY: 1000, visibleHeight: 800, documentHeight: 3100, + ) + #expect(target != nil) + #expect(try abs(#require(target) - 2300) < 0.5) + // Already parked at the clamp: no-op, no jump while typing the tail. + #expect(CaretCentering.targetOffset( + caretY: 3050, visibleMinY: 2300, visibleHeight: 800, documentHeight: 3100, + ) == nil) + } + + @Test func `short document never scrolls`() { + // Document shorter than the viewport: clamp floors at 0. + #expect(CaretCentering.targetOffset( + caretY: 300, visibleMinY: 0, visibleHeight: 800, documentHeight: 400, + ) == nil) + } +} diff --git a/docs/devlog/20261009-issue87-focus-mode_log.md b/docs/devlog/20261009-issue87-focus-mode_log.md new file mode 100644 index 0000000..abf092e --- /dev/null +++ b/docs/devlog/20261009-issue87-focus-mode_log.md @@ -0,0 +1,47 @@ +# Session Log — #87 Build: land focus mode (map #21) + +**Date:** 2026-10-09 +**Branch:** `wayfinder/87-focus-mode` (local, unpushed — push awaits authorization) +**Ticket:** [#87](https://git.babylondreams.de/AlexKucera/museion/issues/87) — build child of map [#21](https://git.babylondreams.de/AlexKucera/museion/issues/21) + +## What happened + +Wayfinder work-through session on map #21 ("M1 focus mode & typographic calm"). Claimed the frontier ticket — the build child. The build IS the prototype; calibration gate #88 judges calm. + +**Pre-flight repairs:** both ticket bodies referenced `@wf21-build.md` / `@wf21-calib.md` assets that never uploaded (asset endpoint 500s server-side at charting time — same failure reproduced this session). Recovered both specs from the charting session's scratch files and baked them into the ticket bodies via API PATCH (verified round-trip). Claimed #87 (assignee AlexKucera, verified via GET). + +**The build (all ACs from the ticket body):** + +- `AppGateState.isFocused` — transient like reading mode (#68): per-launch, no persistence, fresh open lands unfocused. +- View ▸ Toggle Focus Mode (CommandGroup after `.toolbar`, beside Toggle Reading Mode per #84) + ⌘⇧F. Disabled when no post open and no draft — but exit stays armed while focused (trashing the open post from the library overlay must not trap the user in focus). +- WorkspaceView: rail recedes, pane takes full width. PostsPaneView: library + mentor columns recede. PostEditorView: toolbar row recedes; editor ground swaps surface → workspace background (NSColor twin `DesignTokens.workspaceBackground` — SwiftUI Color can't cross into NSTextView). +- `FocusChrome.swift` (new): `HoverZone` (NSTrackingArea edge strip, 14pt, `hitTest → nil` — hover never steals clicks), `FocusOverlayPanel` (slide-in overlay: easeOut 0.2s in / easeIn 0.15s out, 140ms hide grace covering the zone→panel transit; floats OVER the measure, never pushes it), `CaretCentering` (soft caret centering). +- Left-edge hover slides rail+library back in (library only when window ≥1100px — #17's width collapse is not overridden); right-edge hover slides the mentor back in. +- Soft caret centering: ±60pt comfort band around the visible center, `textDidChange` only (scrollback and drag-selection never fought), animated clip-view scroll (0.18s), document clamp parks at the bottom — no jump when typing at the document end. +- `PostsLibraryColumn` extracted from PostsPaneView — one library implementation serving both the unfocused layout and the focus overlay (rename sheet + context menu travel with it). +- Save failure loud in focus: the full SaveStateDot-shaped widget (6px dot + "Save failed") reappears as a floating top overlay when `saveState == .failed`; #67 conflict alert unchanged; autosave runs underneath. +- ⌘S moved from the toolbar into the body-level background — it stays armed with the toolbar hidden (drafts have no autosave; ⌘S is their only save path). +- Focus × reading orthogonal: independent state axes; ⌘R works in focus, ⌘⇧F works while reading. +- `FocusModeTests.swift` (5 tests): the centering band math pinned — in-band no-op, below/above-band recenter, bottom clamp (parks then no-ops), short-document floor. + +## Verification + +- Build green: `xcodebuild build` — BUILD SUCCEEDED. +- Tests green: full suite (`MuseionTests` + UI tests) — TEST SUCCEEDED, FocusModeTests 5/5 passed. +- swiftformat + swiftlint clean on all touched files (PostEditorView's file-length + `tv` identifier warnings pre-exist on main; my change grows the file 424→483). +- Old AC2 verified: width-collapse logic (`showsLibrary`/`showsMentor`) untouched, focus overlay respects it. +- AC3: no typography work (inherits ProseTypography + reading.css per #78). + +## Notable decisions + +- Overlay, not push: revealed panes float above the measure — the measure never moves (charting contract). +- No Esc exit (rejected at charting) — the toggle (menu/⌘⇧F) is the only way out. +- Calibration knobs live in FocusChrome.swift constants (band 60pt, zone width 14pt, animation curves, 140ms grace) — the fog's polish ticket can dial them without archaeology. + +## Deviations / follow-ups + +- Asset endpoint 500s server-side — tickets now carry their specs in-body (repaired for #87 and #88). Charting sessions should verify uploads. +- Visual pass owed: the surface renders (build+tests green) but the calm judgment is the calibration gate #88 — Alexander writes on the pinned corpus and rules. Animation feel and hover-zone sizing are the named fog knobs. +- PostEditorView at 483 lines vs swiftlint's 400 cap (pre-existing 424): candidate for the next drive-by split (ProseTextView representable → own file). + +[Generated by AI] diff --git a/docs/devlog/INDEX.md b/docs/devlog/INDEX.md index feff46c..f848fe9 100644 --- a/docs/devlog/INDEX.md +++ b/docs/devlog/INDEX.md @@ -5,6 +5,7 @@ Complete history of session logs in this directory, newest first. One-line summa | Date | Type | File | Summary | |------|------|------|---------| +| 2026-10-09 | issue | [20261009-issue87-focus-mode_log.md](20261009-issue87-focus-mode_log.md) | #87 focus mode: pane/toolbar recession, hover overlay reveal, soft caret centering — full suite green, calibration gate #88 next | | 2026-10-08 | issue | [20261008-issue84-view-menu-doubled_log.md](20261008-issue84-view-menu-doubled_log.md) | #84 single View menu: CommandMenu → CommandGroup(after: .toolbar), menu-count pin test — 105 tests green | | 2026-10-08 | issue | [20261008-issue83-save-indicator-honesty_log.md](20261008-issue83-save-indicator-honesty_log.md) | #83 honest save dot: Changed while dirty, Saving… deleted, sticky failed, vanished-disk keepLocal fix — 106 tests green | | 2026-10-08 | issue | [20261008-issue77-editing-parity_log.md](20261008-issue77-editing-parity_log.md) | #77 editing parity: reading-mirrored presenter (30/22/19 ladder, inline traits, 66ch measure), fence-staleness audit fix — 104 tests green |