summaryrefslogtreecommitdiff
path: root/core/Trail.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-24 19:30:38 -0300
committerGabriel Schneider <[email protected]>2026-11-24 19:30:38 -0300
commita79de661ee8cf443e88030a9546d06da9fbb4c0b (patch)
tree7de4390ee955e5209eb5d4c27b58d0239841a734 /core/Trail.zig
parent1c4aea3b0298f6f59ffec9b49f4d5e5f38c8af0f (diff)
downloadpardes-a79de661ee8cf443e88030a9546d06da9fbb4c0b.tar.gz
pardes-a79de661ee8cf443e88030a9546d06da9fbb4c0b.zip
walk (pick-ui SPEC §6.4, item 4 of the Walk UI line B): Ctrl-o goes back one place in a reading pane's walk and Ctrl-i forward one (Trail.walkBy, at the head of Jump.jumpBy, so Back, Forward, the keys and the mouse's side buttons all take it), past its first place (its owner's word is no place) or its last, and from a held pane, the jump list's step as before; the hook for Ctrl-i stepping the Walk queue once the pickers make one is a comment where it goes; TEST FIRST: Trail.zig "Ctrl-o goes back one place in a reader's walk and Ctrl-i forward again; past its first place, or from a held pane, the jump list's"; core-test 999/1165 (166 skipped), pane-test 183/184, behaviour-test 277/277
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'core/Trail.zig')
-rw-r--r--core/Trail.zig45
1 files changed, 45 insertions, 0 deletions
diff --git a/core/Trail.zig b/core/Trail.zig
index a198cae5..3faccafa 100644
--- a/core/Trail.zig
+++ b/core/Trail.zig
@@ -222,6 +222,23 @@ pub fn edited(p: *Pardes, f: *const panes.File.State) void {
}
+/// Back (`delta` < 0) or forward one place in reading pane `id`'s walk,
+/// as Ctrl-o and Ctrl-i go first (pick-ui SPEC §6.4): true when it had
+/// one that way, false to leave the step to the jump list (Jump.jumpBy).
+pub fn walkBy(p: *Pardes, id: usize, delta: i32) bool {
+ const pane = p.panes[id] orelse return false;
+ if (!reading(p, pane)) return false;
+ const t = &pane.trail;
+ var i: usize = t.cur;
+ while (if (delta < 0) i > 0 else i + 1 < t.n) {
+ i = if (delta < 0) i - 1 else i + 1;
+ if (t.steps[i] != .place) continue;
+ _ = go(p, id, @intCast(i)) catch |err| p.reportError(.at(id), "walk", err);
+ return true;
+ }
+ return false;
+}
+
// ---- the words ----
pub const Part = enum { back, forward };
@@ -586,3 +603,31 @@ test "a trail keeps its newest three back steps whole, older ones fold to ·, an
try clickTag(p, r, "·", .right);
try std.testing.expectEqualStrings("rank.zig:10", f.at(&at));
}
+
+test "Ctrl-o goes back one place in a reader's walk and Ctrl-i forward again; past its first place, or from a held pane, the jump list's" {
+ var f: Fixture = .{ .p = undefined, .tmp = undefined };
+ try f.init(60);
+ defer f.deinit();
+ const p = f.p;
+ var at: [64]u8 = undefined;
+ f.look(f.held, "rank.zig", 12);
+ f.look(p.view().active, "place.zig", 8);
+ f.look(p.view().active, "place.zig", 40);
+ const back: pardes.Key = .{ .cp = 'o', .ctrl = true };
+ const ahead: pardes.Key = .{ .cp = 'i', .ctrl = true };
+ p.update(.{ .key = back });
+ p.sync();
+ try std.testing.expectEqualStrings("place.zig:8", f.at(&at));
+ p.update(.{ .key = back });
+ p.sync();
+ try std.testing.expectEqualStrings("rank.zig:12", f.at(&at));
+ p.update(.{ .key = ahead });
+ p.sync();
+ try std.testing.expectEqualStrings("place.zig:8", f.at(&at));
+ p.update(.{ .key = back });
+ p.sync();
+ try std.testing.expectEqualStrings("rank.zig:12", f.at(&at));
+ // The owner's word is no place: past the first, the jump list's.
+ try std.testing.expect(!walkBy(p, p.view().active, -1));
+ try std.testing.expect(!walkBy(p, f.held, -1));
+}