summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/Jump.zig4
-rw-r--r--core/Trail.zig45
2 files changed, 49 insertions, 0 deletions
diff --git a/core/Jump.zig b/core/Jump.zig
index a83b6ab4..a4ecca04 100644
--- a/core/Jump.zig
+++ b/core/Jump.zig
@@ -274,6 +274,10 @@ pub fn trackJump(p: *Pardes) void {
/// always have, at the newest entry.
pub fn jumpBy(p: *Pardes, delta: i32) void {
const v = p.view();
+ // A reading pane's walk first (pick-ui SPEC §6.4). Past its newest
+ // step, Ctrl-i is to step the Walk queue once the pickers make one;
+ // until then, the jump list's.
+ if (pardes.Trail.walkBy(p, v.active, delta)) return;
const older = delta < 0;
// At an end of the list: said, not a step that silently does nothing.
if (v.jumps.n == 0 or (older and v.jumps.cur == 0) or (!older and v.jumps.cur + 1 >= v.jumps.n))
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));
+}