summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/Trail.zig19
-rw-r--r--core/panes.zig4
-rw-r--r--test/behaviour/look_and_exec.zig23
-rw-r--r--test/process/window.zig11
4 files changed, 49 insertions, 8 deletions
diff --git a/core/Trail.zig b/core/Trail.zig
index 9223d1d3..5f6302e4 100644
--- a/core/Trail.zig
+++ b/core/Trail.zig
@@ -192,8 +192,11 @@ pub fn replaceStep(p: *Pardes, id: usize, path: []const u8, at: Spot) !usize {
}
/// Pane `id` showing `path` at `at`, the keyboard on it: its caret moved
-/// in the file it shows, or a new pane on `path` in its place, its walk
-/// with it. A line past the new file's end is a miss that changes nothing.
+/// in the file it shows, or `path` opened in its place as the same pane, as
+/// acme's Get keeps a window's id: its walk, its serial (`@pN`, a script's
+/// `/pane/N`), the 9P state its scripts hold and its /log record (a rename),
+/// the file it left closed as any (Recent keeps its place). A line past the
+/// new file's end is a miss that changes nothing.
fn show(p: *Pardes, id: usize, path: []const u8, at: Spot) !usize {
const pane = p.panes[id].?;
if (pane.file) |f| if (std.mem.eql(u8, f.path, path)) {
@@ -211,11 +214,23 @@ fn show(p: *Pardes, id: usize, path: []const u8, at: Spot) !usize {
}
if (at.line > panes.File.nlines(p.gpa, &nt.file.?)) return error.LineMissing;
nt.trail = pane.trail;
+ // What jj answered for the file it leaves goes with that file; its
+ // text a revision on from the one it leaves, so nothing a worker was
+ // asked of that text (a parse, a paint, both by serial and revision)
+ // lands on this one.
+ @import("jj.zig").forget(p, pane.serial);
+ nt.serial = pane.serial;
+ nt.file.?.revision = if (pane.file) |f| f.revision +% 1 else 0;
+ nt.file.?.saved_revision = nt.file.?.revision;
+ // Its 9P state: the one never announced leaves with no record.
+ std.mem.swap(@TypeOf(pane.fs), &nt.fs, &pane.fs);
// Before the layout gives its place away: its file is told closed
// while it is still in its slot.
try panes.deinitPane(p, pane);
layout.replacePane(p, id, free);
p.panes[id] = null;
+ pardes.ctlfs.events.noteLog(p, .rename, nt);
+ if (pardes.Pardes.onDisk(nt)) p.recent.opened(p.recentGpa(), path);
lift(p, free);
look.focusPaneLine(p, free, at, .keep);
// Its line half the body's rows down, as a look's new pane has it.
diff --git a/core/panes.zig b/core/panes.zig
index e4ed3e9d..20a03b25 100644
--- a/core/panes.zig
+++ b/core/panes.zig
@@ -1254,7 +1254,9 @@ pub fn teardownPane(p: *Pardes, pane: *Pane) void {
pane.jump.deinit(p.gpa);
pane.places.deinit(p.gpa);
p.gpa.free(pane.recipe_sels);
- @import("jj.zig").forget(p, pane.serial);
+ // A pane that walked on (Trail.show) is the same pane on another file:
+ // what jj answers now is its own.
+ if (p.paneBySerial(pane.serial) == null) @import("jj.zig").forget(p, pane.serial);
if (pane.query) |q| {
q.deinit(p.gpa);
p.gpa.destroy(q);
diff --git a/test/behaviour/look_and_exec.zig b/test/behaviour/look_and_exec.zig
index a7de93cd..251b6325 100644
--- a/test/behaviour/look_and_exec.zig
+++ b/test/behaviour/look_and_exec.zig
@@ -790,3 +790,26 @@ test "look-and-exec: a look at a directory opens a pane listing it, as acme's di
try std.testing.expectEqualStrings("later", again[1]);
try std.testing.expectEqualStrings("sub/", again[2]);
}
+
+test "look-and-exec: a reading pane that walks to another file is the same pane: its number, an open of its files reading the new text, /log's rename for it, the file it left in Recent" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a.txt", .data = "a\n" });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "b.txt", .data = "b\n" });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ var buf: [4096]u8 = undefined;
+ const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)];
+ const r = try s.lookFile(s.at("{s}/a.txt", .{dir}));
+ const body = try s.hold(s.at("/pane/{d}/body", .{r}), 0);
+ // A step in place: b.txt in the pane a.txt was in.
+ try s.write(s.at("/pane/{d}/look", .{r}), s.at("{s}/b.txt\n", .{dir}));
+ try expectEqual(r, try s.focused());
+ try s.expect(s.at("/pane/{d}/name", .{r}), s.at("{s}/b.txt\n", .{dir}));
+ try std.testing.expectEqualStrings("b\n", try s.readFid(body));
+ s.clunk(body);
+ const log = try s.read("/log");
+ try std.testing.expect(std.mem.endsWith(u8, log, s.at("rename {d} {s}/b.txt\n", .{ r, dir })));
+ try std.testing.expect(std.mem.indexOf(u8, log, s.at("del {d} ", .{r})) == null);
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/recent"), s.at("{s}/a.txt", .{dir})) != null);
+}
diff --git a/test/process/window.zig b/test/process/window.zig
index 59c84616..2a1331ad 100644
--- a/test/process/window.zig
+++ b/test/process/window.zig
@@ -402,10 +402,10 @@ fn corpus(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
defer arena.deinit();
const a = arena.allocator();
defer _ = system("rm -rf -- /tmp/pardes-gui-corpus");
- // Its Looks open panes and Del them by serial, as `Jumps new-pane`
- // does (SPEC ยง6.6): under walk a file pane steps in place, a new
- // serial, and the frames would not be the base's to compare.
- const init = "Shell /bin/sh\nTheme forge\nMessageLinger 0\nCursorBlink off\nJumps new-pane\n";
+ // Jumps walk, the default: the file pane's Looks at files step it in
+ // place, the same pane (its serial kept, Trail.show); a picture's and a
+ // PDF's open panes of their own.
+ const init = "Shell /bin/sh\nTheme forge\nMessageLinger 0\nCursorBlink off\n";
var k: Corpus = .{ .gpa = gpa, .a = a, .out = out };
{
try corpusRoot(a);
@@ -474,7 +474,8 @@ fn corpus(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
const image = try paneWith(f, "ramp.ppm");
try k.keep(&d, 0, "09 an image pane", false);
try f.write(f.at("/pane/{d}/exec", .{image}), "Del\n");
- try f.write(f.at("/pane/{d}/exec", .{notes}), "Del\n");
+ // The file pane walks back to shapes.zig (its trail's step).
+ try f.write(f.at("/pane/{d}/look", .{notes}), root ++ "/shapes.zig\n");
try f.write(f.at("/pane/{d}/look", .{first}), root ++ "/doc.pdf\n");
_ = try paneWith(f, "doc.pdf");
try k.keep(&d, 0, "09 a PDF pane", false);