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:
1 parent
d183d735d7
commit
97893147a6
10 files changed
+259
-52
No files matched your search
@@ -153,6 +153,20 @@ nonisolated enum FixCardStore {
|
||||
return text.ranges(of: quote).count >= occurrence ? .valid : .stale
|
||||
}
|
||||
|
||||
/// #204: the anchor's exact span in `text` — the appliedText math WITHOUT
|
||||
/// the edit: the quote's 1-based non-overlapping occurrence as an NSRange
|
||||
/// a jump can select. nil for every case that must never land: a stale
|
||||
/// anchor (quote gone or occurrence short) or an empty quote. The lane
|
||||
/// never gates here — a demonstration card's anchor is still a real
|
||||
/// place in the text; the palette decides what to offer.
|
||||
static func anchorRange(of card: StoredFixCard, in text: String) -> NSRange? {
|
||||
guard card.anchor.occurrence >= 1, !card.anchor.quote.isEmpty else { return nil }
|
||||
return text.ranges(of: card.anchor.quote)
|
||||
.dropFirst(card.anchor.occurrence - 1)
|
||||
.first
|
||||
.map { NSRange($0, in: text) }
|
||||
}
|
||||
|
||||
// MARK: - Apply (pure)
|
||||
|
||||
/// #25 (S3.2/S3.3): the mechanical Apply as a pure function — the edit
|
||||
@@ -164,12 +178,8 @@ nonisolated enum FixCardStore {
|
||||
/// issue and accept degrade to a loud no-match, never a wrong-span
|
||||
/// patch. The caller owns the ask and the file write.
|
||||
static func appliedText(of card: StoredFixCard, in text: String) -> String? {
|
||||
guard card.lane == .mechanical,
|
||||
card.anchor.occurrence >= 1,
|
||||
!card.anchor.quote.isEmpty,
|
||||
let range = text.ranges(of: card.anchor.quote).dropFirst(card.anchor.occurrence - 1).first
|
||||
else { return nil }
|
||||
return text.replacingCharacters(in: range, with: card.fix)
|
||||
guard card.lane == .mechanical, let range = anchorRange(of: card, in: text) else { return nil }
|
||||
return (text as NSString).replacingCharacters(in: range, with: card.fix)
|
||||
}
|
||||
|
||||
// MARK: - Submit
|
||||
|
||||
Reference in new issue
Block a user