Keyboard ←/→ keep their place — a sticky ordinal that outlives the clamp

Lateral card navigation was pure geometry: the nearest drawn frame in the
direction. That loses the walk in the card's own title — stepping from a
10-card lane's 8th card into a 3-card lane clamps to its 3rd, and coming
back out, "the nearest frame at that height" is the 3rd card's height. The
information the user was walking at stopped being on screen, so no rule
over rectangles could have recovered it.

So it is remembered instead. `TransientBoardState.lateralOrdinal` holds the
1-based position a run of ←/→ started from, counted over the cards the board
is showing, and `NavigationMath.lateralHop` lands each hop on
`min(ordinal, target lane's count)` of the next lane that is showing cards —
collapsed and query-emptied lanes hopped over on `firstCard`'s rule rather
than by the accident of registering no frames. 8th → 3rd → 8th.

Every reset comes from one funnel and needs no enumeration anywhere: the
ordinal is a defaulted `nil` parameter on `select`, so a click, a marquee, a
↑/↓ step, an ⌥-jump, a ⌫ successor, a lane-domain arrow and the reload's
focus recovery all end the run by saying nothing. `resolve` adds the one
rule a value referencing no item can need — the ordinal never outlives the
head it was counted from — while a reload that leaves the cursor standing
leaves the run standing too.

A wide lane's interior masonry columns keep their spatial step and carry the
ordinal through untouched: a column hop is not a lane hop, and stickiness is
lane-granular over the logical order. With no lane in the direction the
geometry has the last word, which is how → still reaches the shown trash.

Claude-Session: https://claude.ai/code/session_014PtZdPwqZuqEDLc6wZMtEy
This commit is contained in:
2026-08-08 23:28:05 -04:00
parent eb950ee881
commit f9f284cac9
6 changed files with 552 additions and 13 deletions
+10 -2
View File
@@ -4799,15 +4799,23 @@ public final class BoardStore: HealHost {
///
/// - Parameter defaultsSoleMember: forwarded verbatim see `TransientBoardState.select`, whose
/// sole-member default the rubber band opts out of.
/// - Parameter lateralOrdinal: forwarded verbatim see `TransientBoardState.lateralOrdinal`,
/// whose `nil` default is what makes every caller here a reset of the / run.
public func select(
_ ids: Set<ItemID>,
in container: ItemContainer,
anchor: ItemID? = nil,
head: ItemID? = nil,
defaultsSoleMember: Bool = true
defaultsSoleMember: Bool = true,
lateralOrdinal: Int? = nil
) {
transient.select(
ids, in: container, anchor: anchor, head: head, defaultsSoleMember: defaultsSoleMember
ids,
in: container,
anchor: anchor,
head: head,
defaultsSoleMember: defaultsSoleMember,
lateralOrdinal: lateralOrdinal
)
transient.noteActiveLane(Self.lane(holding: ids, in: snapshot))
}
+42 -2
View File
@@ -282,6 +282,29 @@ public final class TransientBoardState {
/// by `resolve(against:)` under the same universe rule.
public private(set) var selectionHead: ItemID?
/// **What position in its lane a run of / is holding on to** the sticky ordinal (ruled
/// 2026-08-09), 1-based over the cards the board is *showing*, `nil` when no lateral run is in
/// flight.
///
/// The third memory of a gesture, and the one that exists because a *screen* cannot remember it:
/// stepping from a 10-card lane's 8th card into a 3-card lane clamps to its 3rd, and every rule
/// that reads drawn rectangles `NavigationMath.nearest` included then has only "3rd card"
/// to step back out with. The number the user is walking at survives here instead, unclamped, so
/// the hop back lands on the 8th again (`NavigationMath.lateralHop`).
///
/// **`nil` is a reset, and every existing caller gets one for free**: `select` takes it as a
/// defaulted parameter and stores it verbatim, so a click, a marquee, a / step, an -jump, a
/// successor, a lane-domain arrow and the reload's focus recovery all end the run without any
/// of them naming it. Only the lateral hop passes a value. Reading `nil` on the next hop is not a
/// missing answer either it means "start a run here", which captures the cursor's *actual*
/// position, which is the ruling's "resets to the actual new position" arrived at lazily.
///
/// **An ordinal rather than a card**, deliberately: the thing being preserved is a position in a
/// list, and the lists on either side of a hop are different lanes with different lengths. It
/// therefore references no item, which is why `resolve(against:)` has only one thing to say about
/// it see there.
public private(set) var lateralOrdinal: Int?
/// The items a drag is carrying **empty when no drag is in flight**, which is what "no drag"
/// means here rather than a separate flag.
///
@@ -406,26 +429,33 @@ public final class TransientBoardState {
/// `resolve(against:)` on the next reload is what keeps the set honest over time.
///
/// - Parameter defaultsSoleMember: whether a `nil` anchor or head falls back to a sole member.
/// - Parameter lateralOrdinal: the sticky ordinal a run of / is carrying, or `nil` which is
/// what **every** caller but the lateral hop passes, and is why "a non-lateral selection change
/// resets it" needs no enumeration of the gestures anywhere. See `lateralOrdinal`.
public func select(
_ ids: Set<ItemID>,
in container: ItemContainer,
anchor: ItemID? = nil,
head: ItemID? = nil,
defaultsSoleMember: Bool = true
defaultsSoleMember: Bool = true,
lateralOrdinal: Int? = nil
) {
selection = ItemReferenceSet(ids: ids, container: container)
let sole = defaultsSoleMember && ids.count == 1 ? ids.first : nil
selectionAnchor = anchor ?? sole
selectionHead = head ?? sole
self.lateralOrdinal = lateralOrdinal
}
/// Selects nothing Escape's last step outward (04-interactions.md Grammar). The anchor and
/// the head go with it: an empty selection has no origin to range from and no cursor to step
/// from which is exactly the state the arrows' seed rule answers.
/// from which is exactly the state the arrows' seed rule answers. The sticky ordinal goes for
/// the same reason: there is no run left to be in the middle of.
public func clearSelection() {
selection = .empty
selectionAnchor = nil
selectionHead = nil
lateralOrdinal = nil
}
/// Records that `laneID` is where the user is working a lane selected, or created into.
@@ -681,6 +711,13 @@ public final class TransientBoardState {
if let anchor = selectionAnchor, !universe.contains(anchor) { selectionAnchor = nil }
if let head = selectionHead, !universe.contains(head) { selectionHead = nil }
}
// **The sticky ordinal never outlives the head it was counted from** the one thing a reload
// has to say about a value that references no item. A run of / whose cursor vanished has
// nothing left to be a run *of*, and the next arrow re-derives its head from the selection's
// last member, which is a position the run never named. A reload that leaves the head standing
// deliberately leaves the run standing too: an agent filing a card mid-walk is not the user
// changing their mind.
if selectionHead == nil { lateralOrdinal = nil }
constrainToSearch(in: snapshot, commentMatches: commentMatches)
}
@@ -726,6 +763,9 @@ public final class TransientBoardState {
selection = selection.constrained(to: universe)
if let anchor = selectionAnchor, !universe.contains(anchor) { selectionAnchor = nil }
if let head = selectionHead, !universe.contains(head) { selectionHead = nil }
// A hidden cursor ends the lateral run, for `resolve`'s reason: the ordinal counts what the
// user can see, and a run stepping from a card the filter took away counts from nowhere.
if selectionHead == nil { lateralOrdinal = nil }
}
/// The placeholder's two discard rules, as a pure function of the placeholder and the snapshot.
+56 -8
View File
@@ -1131,19 +1131,67 @@ struct BoardView: View {
///
/// Every registered target is a candidate, which is also how the hidden trash stays invisible:
/// a column that is not drawn registers nothing.
///
/// **/ across lanes are the one exception, and they answer from the sticky ordinal instead**
/// (ruled 2026-08-09; `NavigationMath.lateralHop`): a lane hop lands on the position the run is
/// holding, clamped to the target lane, so 10-3-10 walks out and back to the same card. The three
/// branches below are ordered by how specific they are
///
/// 1. **A same-lane neighbour wins first**, which is a wide lane's interior masonry column. That
/// is a column hop, not a lane hop, so it keeps its geometry *and* leaves the run's ordinal
/// exactly as it found it "interior masonry position does not participate".
/// 2. **Otherwise the lanes decide**, and the ordinal picks the card in the lane they name. The
/// collapsed and query-emptied lanes are skipped inside `lateralHop`, on `firstCard`'s rule
/// rather than by the accident of registering no frames.
/// 3. **With no lane that way, geometry has the last word** which is how `` off the last lane
/// still reaches the shown trash, and how the trash's own / stay spatial (an origin over
/// there is not in `.board` at all, so branch 2 never sees it).
private func step(_ direction: NavigationMath.Direction, from head: ItemID) -> KeyPress.Result {
guard let origin = marqueeTargets.targets[head],
let nextID = NavigationMath.nearest(
from: origin.frame,
direction: direction,
among: marqueeTargets.all
),
let next = marqueeTargets.targets[nextID]
else { return .handled }
guard let origin = marqueeTargets.targets[head] else { return .handled }
let geometric = NavigationMath.nearest(
from: origin.frame,
direction: direction,
among: marqueeTargets.all
)
if direction == .left || direction == .right, origin.container == .board {
let sticky = store.transient.lateralOrdinal
if let geometric, let home = lane(holding: head), lane(holding: geometric) == home {
store.select(
[geometric], in: .board, anchor: geometric, head: geometric, lateralOrdinal: sticky
)
return .handled
}
if let hop = NavigationMath.lateralHop(
from: head,
direction,
scanning: boardLanes,
filter: store.searchFilter,
sticky: sticky
) {
store.select(
[hop.target],
in: .board,
anchor: hop.target,
head: hop.target,
lateralOrdinal: hop.ordinal
)
return .handled
}
}
guard let nextID = geometric, let next = marqueeTargets.targets[nextID] else { return .handled }
replaceSelection(with: next.id, in: next.container)
return .handled
}
/// The live lane `card` sits in, or `nil` for anything the board is not showing as a card a
/// trash row included, which is what makes the same-lane test above reject a crossing candidate
/// without a second container check.
private func lane(holding card: ItemID) -> ItemID? {
store.snapshot.lanes.first { $0.cards.contains { $0.id == card } }?.id
}
/// **-arrow extends, and stops at the container boundary** (04 The trash: "-arrow extension
/// still stops at the container boundary") a -arrow whose next step would cross from live
/// cards into the trash, or back, is simply inert.
+77
View File
@@ -116,6 +116,83 @@ public enum NavigationMath {
}
return nil
}
// MARK: The sticky ordinal
/// Where a lateral hop lands, and the ordinal it carries onward `lateralHop`'s answer.
public struct LateralHop: Sendable, Equatable {
/// The card to select.
public let target: ItemID
/// The ordinal the *sequence* is holding the origin's, **unclamped**, so a walk through a
/// short lane and out the other side remembers where it started rather than where it was
/// squeezed to. `TransientBoardState.lateralOrdinal` stores exactly this.
public let ordinal: Int
public init(target: ItemID, ordinal: Int) {
self.target = target
self.ordinal = ordinal
}
}
/// **/ preserve the origin's position in its lane** (ruled 2026-08-09): a lateral hop lands on
/// the `min(sticky, count)`-th card of the adjacent lane, counting the cards the board is
/// *showing*, so the 10-3-10 walk in the card's title round-trips 8th 3rd (clamped) 8th.
///
/// Geometry cannot do this and the failure is not a bug in the score: `nearest` picks the frame
/// closest to the origin's height, and after a clamp into a short lane the origin's height *is*
/// the short lane's 3rd card. Every candidate rule over drawn rectangles loses the same
/// information, because the information "the user was 8 cards down" stopped being on screen.
/// So the ordinal is remembered instead (`TransientBoardState.lateralOrdinal`), and this function
/// is the only thing that reads it.
///
/// **The lanes it walks are the showing ones**, which is `firstCard`'s rule with one addition,
/// and the three skips are the same three: a collapsed lane draws no card faces, a lane the query
/// emptied shows none either, and an empty lane has none to show. A hop is *one* showing lane
/// over never "the next lane, unless it is folded, in which case two" spelled at a call site.
///
/// **Ordinals are lane-granular and read the logical order** (10-accessibility.md's rule, and the
/// one `SortMath` moves along): a wide lane's masonry columns are a rendering, so the 8th card is
/// the 8th in `order` whichever interior column it was laid into. The *interior* step keeps its
/// geometry `BoardView.step` takes a same-lane neighbour before it ever asks this because a
/// lane hop and a column hop are different gestures wearing one key.
///
/// - Parameters:
/// - origin: the card the cursor is on. Not a frame: this rule is about lanes and lists, and
/// taking a rectangle would invite the geometry back in.
/// - sticky: the ordinal the sequence is already carrying, or `nil` to **start** one here
/// which captures the origin's own ordinal, and is what makes "the first hop of a sequence"
/// need no flag of its own.
/// - Returns: `nil` when the direction is vertical, when `origin` is not in a showing lane, or
/// when there is no showing lane that way the last of which is `BoardView.step`'s cue to fall
/// back to geometry, so `` still reaches the shown trash off the last lane.
public static func lateralHop(
from origin: ItemID,
_ direction: Direction,
scanning lanes: some Sequence<Lane>,
filter: SearchFilter = .inactive,
sticky: Int? = nil
) -> LateralHop? {
guard direction == .left || direction == .right else { return nil }
let showing: [[ItemID]] = lanes.compactMap { lane in
guard !LaneLayoutMath.isCollapsed(lane) else { return nil }
let ids = lane.cards.filter { filter.matches($0) }.map(\.id)
return ids.isEmpty ? nil : ids
}
guard let home = showing.firstIndex(where: { $0.contains(origin) }),
let position = showing[home].firstIndex(of: origin)
else { return nil }
let carried = sticky ?? (position + 1)
let next = home + (direction == .left ? -1 : 1)
guard showing.indices.contains(next) else { return nil }
let landing = showing[next]
return LateralHop(target: landing[min(carried, landing.count) - 1], ordinal: carried)
}
}
// MARK: - Within-lane sort