summaryrefslogtreecommitdiff
path: root/src/File.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/File.zig')
-rw-r--r--src/File.zig18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/File.zig b/src/File.zig
index 17399d8b..5f6d7097 100644
--- a/src/File.zig
+++ b/src/File.zig
@@ -64,6 +64,9 @@ pub const State = struct {
/// Put does (exec.c:577, "modified since last read").
disk_newer: ?u64 = null,
disk_newer_warned: bool = false,
+ /// Its file was deleted on disk: said once (`deleted`) until it is
+ /// written or found again.
+ disk_gone: bool = false,
/// Seconds of the last content change, for the filesystem's stat; zero until edited.
mtime: u32 = 0,
/// Non-null for a generated output buffer rather than an on-disk file.
@@ -970,6 +973,20 @@ pub fn redo(p: *Pardes, pane: *Pane) void {
restoreSnap(pane, f, next);
}
+/// A pane's file deleted on disk: the text stays, and it says so once,
+/// `<file> deleted on disk (Save writes it again)`, logged `changed
+/// <serial> deleted`.
+pub fn deleted(p: *Pardes, id: u8) void {
+ const pane = p.panes[id] orelse return;
+ const f = if (pane.file) |*file| file else return;
+ if (f.disk_gone) return;
+ f.disk_gone = true;
+ var said: [limits.host_path_cap + 64]u8 = undefined;
+ p.setMessage(id, std.fmt.bufPrint(&said, "{s} deleted on disk (Save writes it again)", .{f.path}) catch "deleted on disk (Save writes it again)");
+ var rec: [32]u8 = undefined;
+ pardes.ctlfs.events.notePath(p, "changed", std.fmt.bufPrint(&rec, "{d} deleted", .{pane.serial}) catch "");
+}
+
/// A file rewritten on disk. A clean buffer takes the new text, committed
/// onto the same undo history as typed edits. A buffer with unsaved edits
/// is never reloaded under them: it keeps its text and stays dirty, and
@@ -981,6 +998,7 @@ pub fn redo(p: *Pardes, pane: *Pane) void {
pub fn changed(p: *Pardes, id: u8, bytes: []const u8) void {
const pane = p.panes[id] orelse return;
const f = if (pane.file) |*file| file else return;
+ f.disk_gone = false;
if (std.mem.eql(u8, f.content, bytes)) return;
if (f.saved_hash) |saved| if (f.revision != f.saved_revision and std.hash.Wyhash.hash(0, f.content) != saved) {
const disk = std.hash.Wyhash.hash(0, bytes);