diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ninep/ctl.zig | 60 | ||||
| -rw-r--r-- | src/pardes.zig | 11 |
2 files changed, 68 insertions, 3 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(); diff --git a/src/pardes.zig b/src/pardes.zig index 5fdcfe3c..d9c69921 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -6705,9 +6705,14 @@ pub const Pardes = struct { const from = p.active; look.reopenAt(p, from, e.path, .{ .line = @max(1, j.line), .col = @max(1, j.col) }); const opened = p.panes[p.active] orelse return; - if (p.active == from) return; - p.jumps[@intCast(next)].pane = @intCast(p.active); - p.jumps[@intCast(next)].serial = opened.serial; + const f = opened.file orelse return; + if (!std.mem.eql(u8, f.path, e.path)) return; // it did not open + // Every entry of that file is the reopened pane from here on, so + // a step onto another of them moves in it rather than reopening. + for (p.jumps[0..p.njumps]) |*k| if (k.serial == 0 and k.path_hash == j.path_hash) { + k.pane = @intCast(p.active); + k.serial = opened.serial; + }; p.jcur = @intCast(next); return; } |
