summaryrefslogtreecommitdiff
path: root/src/ninep/ctl.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-29 11:11:09 -0300
committerGabriel Schneider <[email protected]>2026-10-01 00:12:16 -0300
commit536df266a4af38cf20ecb340337a6de2922e8902 (patch)
treef283e2854bac73f012a90e2ea675b134350b1e9d /src/ninep/ctl.zig
parent5db9e71ba32dd6f0a0292eaa341d1d8ba805483c (diff)
downloadpardes-536df266a4af38cf20ecb340337a6de2922e8902.tar.gz
pardes-536df266a4af38cf20ecb340337a6de2922e8902.zip
One reopen of a closed file is that file's pane in every jumplist entry
A Back that reopened a file updated only the entry it stepped onto; another entry for the same file stayed closed, and stepping onto it re-looked the file, found it already active and returned without moving, so Forward (or Back) did nothing. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/ninep/ctl.zig')
-rw-r--r--src/ninep/ctl.zig60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index 889ee7be..9bb863cf 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -2163,6 +2163,66 @@ test "a closed file is found again: Recent and /recent list it closed, a look at
try testing.expectEqualStrings(a, p.panes[p.active].?.file.?.path);
}
+test "Back and Forward over a closed file's entries: one reopen is that file's pane in every entry, so the next step moves" {
+ const p = try withFile(testing.allocator, "x\n");
+ defer p.deinit();
+ var tmp = testing.tmpDir(.{});
+ defer tmp.cleanup();
+ var long: [400]u8 = undefined;
+ var n: usize = 0;
+ for (0..100) |_| {
+ @memcpy(long[n..][0..4], "row\n");
+ n += 4;
+ }
+ try tmp.dir.writeFile(testing.io, .{ .sub_path = "a.txt", .data = long[0..n] });
+ try tmp.dir.writeFile(testing.io, .{ .sub_path = "b.txt", .data = "bee\n" });
+ try tmp.dir.writeFile(testing.io, .{ .sub_path = "c.txt", .data = "sea\n" });
+ var dir_buf: [4096]u8 = undefined;
+ const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)];
+ var line: [4200]u8 = undefined;
+ _ = wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/b.txt\n", .{dir}));
+ p.sync();
+ const b_serial = p.panes[p.active].?.serial;
+ // Two entries for a.txt, far apart in it.
+ _ = wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/a.txt:1\n", .{dir}));
+ p.sync();
+ const a = p.active;
+ _ = wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/a.txt:90\n", .{dir}));
+ p.sync();
+ _ = wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/c.txt\n", .{dir}));
+ p.sync();
+ const c_serial = p.panes[p.active].?.serial;
+ _ = wr(p, Node.of(p.panes[a].?.serial, .ctl), "Del\n");
+ p.sync();
+ var closed: usize = 0;
+ for (p.jumps[0..p.njumps]) |j| closed += @intFromBool(j.serial == 0);
+ try testing.expectEqual(@as(usize, 2), closed);
+ // Back reopens it at line 90: both its entries are that pane now.
+ p.jumpBy(-1);
+ p.sync();
+ const re = p.panes[p.active].?;
+ try testing.expect(std.mem.endsWith(u8, re.file.?.path, "/a.txt"));
+ try testing.expectEqual(@as(i32, 89), re.body.cur_row);
+ for (p.jumps[0..p.njumps]) |j| try testing.expect(j.serial != 0);
+ // Back again goes to its line 1, in the same pane, then to b.
+ p.jumpBy(-1);
+ p.sync();
+ try testing.expectEqual(re.serial, p.panes[p.active].?.serial);
+ try testing.expectEqual(@as(i32, 0), re.body.cur_row);
+ p.jumpBy(-1);
+ p.sync();
+ try testing.expectEqual(b_serial, p.panes[p.active].?.serial);
+ // And Forward walks it all again, to c.
+ p.jumpBy(1);
+ p.sync();
+ p.jumpBy(1);
+ p.sync();
+ try testing.expectEqual(@as(i32, 89), re.body.cur_row);
+ p.jumpBy(1);
+ p.sync();
+ try testing.expectEqual(c_serial, p.panes[p.active].?.serial);
+}
+
test "a remembered place is clamped to the file as it is now, its selection's two ends kept where they fit" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();