feat(fix-cards): jump to the anchor

Jump on a Fix Card selects the anchor's span in the piece's
editor and makes the main window key (#204). The span is the
card's quote at its 1-based occurrence, resolved against the
LIVE session text so a dirty buffer still lands, and it rides
the reading flip-back's caret rail: caretHint widens from a
(location, token) tuple to FixCardRevealRequest (SwiftLint
large_tuple), one shared token counter so a jump and a flip-back
can never collide, a zero-length range stays a bare caret and a
non-zero range selects. A jump leaves reading mode first
(reading = false, not exitReading, which stamps its own
zero-length hint), writes nothing, and re-fires per click.

The palette offers Jump on every non-stale card that still shows
an action row; stale anchors have nothing to land on. The
landing math is ProseTextView.landingSpan - a bare caret hops
past leading blanks, a span never does (a quote that IS the
leading blanks selects those blanks) - and appliedText now
routes through anchorRange so Apply and Jump share one
occurrence math.

Two review rounds closed the view-layer gaps the pure pins
could not see: a jump dropped in reading mode; a main window
that never became key (NSApp.activate is a no-op once the
palette's click activated the app - the Coordinator makes
tv.window key instead); a cursor record taken before the scroll.

+3 tests (anchorRange occurrence math with a UTF-16 fixture, the
model's reveal stamp, landingSpan), each flip-verified. Rail
732/732; SwiftFormat and SwiftLint clean. DOX: Museion/AGENTS,
MuseionTests/AGENTS, GLOSSARY gains Jump.
This commit is contained in:
AlexKucera committed 2026-12-03 17:48:55 +01:00
1 parent d183d735d7
commit 97893147a6
10 files changed
+259 -52

No files matched your search

+1 -1
View File
@@ -41,7 +41,7 @@ Conventions every suite follows. Per-suite pin inventories are NOT kept here —
- `PostsModelDepartureTests` — brief-25/#198: document departure guarded — a navigation whose outgoing flush fails (injected read-only dirs) or hits an unanswered #67 conflict aborts and retains the dirty session/guest; #200: quit-time shutdown pins — foreign disk body untouched across a conflicted shutdown, clean dirty session and the open guest flush, a never-loaded session's retyped words refuse (vacuous-flush gap).
- `MicropubTests`, `MicropubModelTests`, `MicropubMediaTests` — publish wire contract, model flow, media/illustration surface.
- `MCPToolsTests`, `MCPServerWireTests`, `MCPToolsPromoteTests`, `ToolPayloadsTests`, `LearningsPaneTests`, `LearningDecayTests` — museion-tools store, wire, promote, tool-payload decoder shapes (strict + lenient, #177), learnings pane, decay.
- `FixCardApplyTests` — fix-card apply/skip/done lifecycle.
- `FixCardApplyTests` — fix-card apply/skip/done lifecycle; #204: the jump-to-the-anchor pins (`anchorRange` occurrence math incl. UTF-16, the model's `revealCard` request stamp, the editor's `landingSpan` — a bare caret hops past leading blanks, a jump span never does).
- `PostsModelTests`, `PassRunTests`, `BlindReadTests`, `EngineLifecycleTests`, `SessionLifecycleTests`, `SessionScopeTests`, `TranscriptRailTests` — model orchestration over the scripted in-process engine (#178): passes, blind read, per-surface engines, session lifecycle, scoped hosting, the typed transcript rail (#177 — speaker/notice type facts through the scripted engine, prefix-free invariant, append-seam classifiers), and the #179 write-rail pins in PostsModelTests (write → one library refresh + strip cleared; failed write owns the strip; nil-Home refuses cleanly; import batch keeps per-file strip messages; mid-pass Home repoint refuses the advance — `endHeldPrompt` is the rig hook that ends a held turn normally, polled to via `hasHeldPrompt` first: `runningPass` flips before the one-shot engine parks its prompt, so firing into that window false-fails under load).
- `DeslopLintTests` (with the `DeslopLintWiringTests` member) — native lint findings, config story, emit loop.
- `EditorSessionTests`, `ReadingPresenterTests`, `ProsePresenterTests`, `FocusModeTests`, `ImportExternalTests`, `ImageIngestTests` — editor session, reading pipeline, editing-surface parity, focus math, import, image ingest + the 27.2 drag-routing seam (`DragInfoStub`, the suite's NSDraggingInfo mock: a Finder-shaped drag routes through the text view and never pastes the path; text-only drags keep the stock drop; outline rows bounce; the probe follows `changeCount`; web URLs and vanished files refuse with the right notice) + the one router's pins (guest, Cold Turkey refusal, ingest hand-off, mixed refusal).
+107 -1
View File
@@ -14,6 +14,16 @@
// card closes applied), skip and done flip only the status, and the stale
// anchor selects and changes no text while the card flags itself stale.
//
// #204 — Scenario: the card points, the editor lands
// From issue #204: a Fix Card should let the writer jump to the relevant
// paragraph — the palette's Jump hands the editor the anchor's exact span.
// Given an open piece carrying a fix card whose anchor is valid,
// when the writer clicks Jump on that card,
// then the model stamps one reveal request carrying the anchor's NSRange
// resolved against the LIVE session text (a dirty buffer still lands),
// the request's token advances so repeated jumps re-fire, nothing is
// written (not text, not the card), and a stale anchor stamps nothing.
//
import Foundation
@testable import Museion
@@ -284,7 +294,103 @@ struct FixCardApplyTests {
#expect(!FileManager.default.fileExists(atPath: folder.appendingPathComponent("post.md").path)) // nothing written
}
// MARK: Promote (#26, S4.1)
// MARK: Jump to the anchor (#204)
/// #204: the pure anchor-span math — the appliedText occurrence rule
/// (1-based, non-overlapping) answered as a range, with every
/// must-never-land case nil.
@Test func `anchorRange resolves the nth occurrence and nils every unlandable case`() throws {
let piece = try makePiece()
let written = try FixCardStore.submit(
piecePath: piece.path,
cards: [
card(quote: "anchor sentence"),
card(quote: "anchor sentence", occurrence: 2),
card(quote: "vanished quote", occurrence: 1),
card(quote: "anchor sentence", lane: .demonstration),
],
)
// submit refuses an empty quote and occurrence 0 at the trust
// boundary — the unlandable-input cases are pinned through the
// stored shape directly.
let emptyQuote = FixCardStore.StoredFixCard(
id: UUID(), submittedAt: Date(), rank: nil, pattern: "p", problem: "p",
diagnosticQuestion: "", fix: "", anchor: .init(quote: "", occurrence: 1),
lane: .mechanical, emitter: .lint, provenance: nil, status: .open, anchorStatus: .stale, promotedAt: nil,
)
let zeroOccurrence = FixCardStore.StoredFixCard(
id: UUID(), submittedAt: Date(), rank: nil, pattern: "p", problem: "p",
diagnosticQuestion: "", fix: "", anchor: .init(quote: "anchor", occurrence: 0),
lane: .mechanical, emitter: .lint, provenance: nil, status: .open, anchorStatus: .stale, promotedAt: nil,
)
let text = "The anchor sentence. And the anchor sentence again."
let first = try #require(FixCardStore.anchorRange(of: written[0].card, in: text))
#expect((text as NSString).substring(with: first) == "anchor sentence")
#expect(first.location == 4) // 1-based, the FIRST match
let second = try #require(FixCardStore.anchorRange(of: written[1].card, in: text))
#expect(second.location == 29) // occurrence 2 — not the first
#expect(FixCardStore.anchorRange(of: written[2].card, in: text) == nil) // stale
// A demonstration card's anchor is still a real place in the text.
#expect(FixCardStore.anchorRange(of: written[3].card, in: text) != nil)
#expect(FixCardStore.anchorRange(of: emptyQuote, in: text) == nil)
#expect(FixCardStore.anchorRange(of: zeroOccurrence, in: text) == nil)
// The range is UTF-16 (NSTextView's unit), not Characters — a grapheme
// before the anchor is 2 units here; a Character-counted location would say 6.
let wide = FixCardStore.anchorRange(of: written[0].card, in: "✍️ The anchor sentence.")
#expect(wide?.location == 7)
}
/// #204: a jump selects the anchor exactly where it resolved; only a bare
/// caret (the #71 flip-back) hops past leading blanks — a quote that IS
/// the leading blanks must select those blanks, never the title. Both
/// shapes clamp to the text.
@Test @MainActor func `landingSpan hops only a bare caret and clamps both shapes to the text`() {
let text = "\n\n\nTitle line."
let jump = FixCardRevealRequest(range: NSRange(location: 0, length: 3), token: 1)
#expect(ProseTextView.landingSpan(for: jump, in: text) == NSRange(location: 0, length: 3)) // the blank run itself
let caret = FixCardRevealRequest(range: NSRange(location: 0, length: 0), token: 2)
#expect(ProseTextView.landingSpan(for: caret, in: text) == NSRange(location: 3, length: 0)) // hops to the title
let over = FixCardRevealRequest(range: NSRange(location: 10, length: 50), token: 3)
#expect(ProseTextView.landingSpan(for: over, in: text) == NSRange(location: 10, length: 4)) // clamped
}
/// #204: the model stamps ONE reveal request per jump — the range
/// resolved against the LIVE session text (dirty buffer included), the
/// token advancing so a repeated jump re-fires; a stale anchor stamps
/// nothing. No write of any kind.
@Test @MainActor func `revealCard stamps a reveal request against the live text and writes nothing`() throws {
let (model, home) = try makeModelHome()
let post = try PostStore.writeNew(body: "# Carded\n\nThe anchor sentence.\n", home: home)
let folder = try #require(PostStore.folder(of: post.id, home: home))
let written = try FixCardStore.submit(
piecePath: folder.path,
cards: [card(quote: "anchor sentence"), card(quote: "vanished quote")],
)
model.select(post.id)
let session = try #require(model.session)
// The writer typed since the last flush — the jump must resolve
// against the buffer, not disk (the range would otherwise drift).
session.edit("# Carded\n\nIntro line.\nThe anchor sentence.\n")
let before = try Data(contentsOf: folder.appendingPathComponent("post.md"))
model.revealCard(written[0].card)
let request = try #require(model.revealRequest)
#expect(request.range.location == (session.text as NSString).range(of: "anchor sentence").location)
#expect(request.range.length == ("anchor sentence" as NSString).length) // UTF-16 units — what NSTextView selects
let token = request.token
#expect(try Data(contentsOf: folder.appendingPathComponent("post.md")) == before) // no write
#expect(try FixCardStore.scan(pieceURL: folder).allSatisfy { $0.status == .open }) // card untouched
// A repeated jump re-fires (the editor applies once per token).
model.revealCard(written[0].card)
#expect(model.revealRequest?.token == token + 1)
// A stale anchor stamps nothing — the previous request stands.
model.revealCard(written[1].card)
#expect(model.revealRequest?.token == token + 1)
}
/// Scenario: the mentor remembers — promoting through the model writes
/// the Learning under the open piece's Home, refreshes the palette's