diff options
| -rw-r--r-- | core/Jump.zig | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/core/Jump.zig b/core/Jump.zig index b28698ee..3d69d6c9 100644 --- a/core/Jump.zig +++ b/core/Jump.zig @@ -302,6 +302,15 @@ pub fn jumpBy(p: *Pardes, delta: i32) void { } next = pick orelse next; }; + // A reading pane with steps after where it is (a step back left them, + // SPEC ยง6.4): a closed file's entry would open in it as a new step, + // which drops them, its list's and search's words among them (UX L). + // The jump list never rewrites a trail: it passes such entries by. + if (p.panes[v.active]) |here| if (pardes.Trail.reading(p, here) and here.trail.cur + 1 < here.trail.n) while (v.jumps.list[next].serial == 0) { + if (if (older) next == 0 else next + 1 >= v.jumps.n) + return p.setMessage(.at(v.active), if (older) "Back: nothing further back" else "Forward: nothing further on"); + next = if (older) next - 1 else next + 1; + }; const j = v.jumps.list[next]; if (j.pane >= MAX_PANES) return; // A closed file's entry: opened again at its dot, placed as a look @@ -451,3 +460,58 @@ test "jump history terminal rectangle follows output and clears on reflow" { try std.testing.expect(pane.pointerSelection(pane.sel[0]) == null); try std.testing.expectEqual(.none, pane.sel[0].state); } + +test "Ctrl-o at a walk's first place never rewrites its trail (UX L): after SPC f f words, Enter, /in_word, Enter, Ctrl-o goes to the first place, a second Ctrl-o leaves the list's and the search's words where they are, and Ctrl-i goes forward again" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 84, .rows = 20 }); + defer p.deinit(); + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + var text: [60 * 16]u8 = undefined; + var w: std.Io.Writer = .fixed(&text); + for (1..61) |n| try w.print("{s} {d}\n", .{ if (n % 12 == 4) "in_word" else "line", n }); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "words.zig", .data = w.buffered() }); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "main.zig", .data = "const words = @import(\"words.zig\");\npub fn main() void {}\n" }); + var dir_buf: [std.Io.Dir.max_path_bytes]u8 = undefined; + const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)]; + // main.zig the session's one pane, as `pardes main.zig` opens it. + const main = try p.setTestFile("const words = @import(\"words.zig\");\n"); + p.gpa.free(main.file.?.path); + main.file.?.path = try std.Io.Dir.path.join(p.gpa, &.{ dir, "main.zig" }); + p.sync(); + p.settings.jumps = .walk; + p.stream.engine = .walk; + const typeKeys = struct { + fn f(pp: *Pardes, keys: []const u8) void { + for (keys) |c| pp.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + } + }.f; + typeKeys(p, " ffwords"); + var n: usize = 0; + while (n < 50 and (pardes.Pick.busy(p) or p.stream.busyFor(pardes.Pick.live(p).?.id))) : (n += 1) { + pardes.Stream.step(p); + p.update(.tick); + } + p.update(.{ .key = .{ .cp = pardes.Key.enter } }); + p.sync(); + typeKeys(p, "/in_word"); + p.update(.{ .key = .{ .cp = pardes.Key.enter } }); + p.sync(); + const back: pardes.Key = .{ .cp = 'o', .ctrl = true }; + const ahead: pardes.Key = .{ .cp = 'i', .ctrl = true }; + const Want = struct { file: []const u8, cur: u8 }; + for ([_]struct { key: pardes.Key, want: Want }{ + .{ .key = back, .want = .{ .file = "main.zig", .cur = 0 } }, + .{ .key = back, .want = .{ .file = "main.zig", .cur = 0 } }, + .{ .key = ahead, .want = .{ .file = "words.zig", .cur = 3 } }, + .{ .key = ahead, .want = .{ .file = "words.zig", .cur = 3 } }, + }) |step| { + p.update(.{ .key = step.key }); + p.sync(); + const pane = p.panes[p.view().active].?; + const t = &pane.trail; + try std.testing.expectEqualStrings(step.want.file, std.Io.Dir.path.basename(pane.file.?.path)); + try std.testing.expectEqual(@as(u8, 4), t.n); + try std.testing.expectEqual(step.want.cur, t.cur); + try std.testing.expect(t.steps[1] == .list and t.steps[2] == .search); + } +} |
