summaryrefslogtreecommitdiff
path: root/core/edit_cmd.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/edit_cmd.zig')
-rw-r--r--core/edit_cmd.zig30
1 files changed, 30 insertions, 0 deletions
diff --git a/core/edit_cmd.zig b/core/edit_cmd.zig
index 8fbde726..7efa98bc 100644
--- a/core/edit_cmd.zig
+++ b/core/edit_cmd.zig
@@ -417,6 +417,10 @@ fn commit(p: *Pardes, pd: *Pending, outputs: []const []const u8) void {
return p.reportError(.at(at), "Edit", err);
};
panes.File.load(p, pf, new);
+ // An edit, though made as a new text: a reading pane it
+ // changes is held (pick-ui SPEC ยง6.5), or a jump from it
+ // would step it off its unsaved text.
+ pardes.Trail.edited(p, pf);
}
}
if (ops.len > 0 or f.moved) ninep_pane.setFileDot(p.settings.tab, pane, sam.moveDot(f.dot, ops));
@@ -803,3 +807,29 @@ test "e and r say a file that cannot be read as Get says it" {
try testing.expect(std.mem.indexOf(u8, r.reply.ename, c[1]) != null);
}
}
+
+test "an Edit's change holds the reading pane it changes, as a typed one does: a Look from it after opens its reader, and the change stays in it" {
+ var tmp = testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(testing.io, .{ .sub_path = "notes.txt", .data = "one\ntwo\nthree\n" });
+ try tmp.dir.writeFile(testing.io, .{ .sub_path = "big.txt", .data = "big\n" });
+ var dir_buf: [4096]u8 = undefined;
+ const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)];
+ const p = try th.withFile(testing.allocator, "scratch\n");
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ var path: [4200]u8 = undefined;
+ // The notes in a reading pane (the first walked to them).
+ look.lookAt(p, 0, try std.fmt.bufPrint(&path, "{s}/notes.txt", .{dir}));
+ const notes = p.view().active;
+ try testing.expect(pardes.Trail.reading(p, p.panes[notes].?));
+ try testing.expectEqual(tree.Status.ok, th.wr(p, tree.Node.of(p.panes[notes].?.serial, .ctl), "Edit 3a/ an edit/\n").reply.status);
+ try testing.expectEqualStrings("one\ntwo\nthree\n an edit", p.panes[notes].?.file.?.content);
+ try testing.expect(!pardes.Trail.reading(p, p.panes[notes].?));
+ // A Look from it: its reader, under it; the notes and their change kept.
+ look.lookAt(p, notes, try std.fmt.bufPrint(&path, "{s}/big.txt", .{dir}));
+ const reader = p.view().active;
+ try testing.expect(reader != notes);
+ try testing.expectEqualStrings("big.txt", std.Io.Dir.path.basename(p.panes[reader].?.file.?.path));
+ try testing.expectEqualStrings("one\ntwo\nthree\n an edit", p.panes[notes].?.file.?.content);
+}