From dc4dd3bc25b11721ab3ad3fccbaea1de54b9fb90 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 1 Oct 2026 22:52:51 -0300 Subject: A file whose disk text is what its unsaved pane was read or saved as is no change on disk: an Undo back across Get file or Edit's e to unsaved edits no longer says the file changed, and Save writes it Co-Authored-By: Claude Opus 5.5 --- src/ninep/ctl.zig | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/ninep') diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 917c9c39..c6b76d51 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -2073,6 +2073,39 @@ test "a bad Tab width and a bad Incl directory are refused invalid, changing not try testing.expect(th.logHas(p, try std.fmt.bufPrint(&rec, "rename {d} /tmp/pardes-twin-renamed.txt\n", .{twin}))); } +test "Undo to unsaved text under its old name says nothing changed on disk when nothing did, and Save then writes" { + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(testing.io, .{ .sub_path = "e.txt", .data = "e\n" }); + try tmp.dir.writeFile(testing.io, .{ .sub_path = "b.txt", .data = "b\n" }); + var dir_buf: [4096]u8 = undefined; + const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; + for ([_][]const u8{ "Get b.txt", "Edit e b.txt" }) |load| { + const p = try withFile(testing.allocator, "x\n"); + defer p.deinit(); + const serial = serialOf(p); + const pane = p.panes[0].?; + var name: [4300]u8 = undefined; + _ = wr(p, Node.of(serial, .name), try std.fmt.bufPrint(&name, "{s}/e.txt\n", .{dir})); + try testing.expect(p.executeBuiltinLine(0, "Get")); + _ = wr(p, Node.of(serial, .body), "appended\n"); + // Asked once, then loaded. + try testing.expect(p.executeBuiltinLine(0, load)); + try testing.expect(p.executeBuiltinLine(0, load)); + try testing.expectEqualStrings("b\n", pane.file.?.content); + try testing.expect(p.executeBuiltinLine(0, "Undo")); + try testing.expectEqualStrings("e\nappended\n", pane.file.?.content); + try testing.expect(pane_files.dirtyOf(pane)); + // The watch looks again at e.txt, as it was all along. + pardes.panes.File.changed(p, 0, "e\n"); + try testing.expectEqual(@as(?u64, null), pane.file.?.disk_newer); + try testing.expect(!th.logHas(p, "changed on disk")); + // A change there is still news. + pardes.panes.File.changed(p, 0, "someone else\n"); + try testing.expect(pane.file.?.disk_newer != null); + } +} + test "a body write to a terminal is typed input, not a paste, even to a program that asked for bracketed paste" { const p = try Pardes.init(testing.allocator, .{ .cols = 90, .rows = 30 }); defer p.deinit(); -- cgit v1.3