From 304a62dfdc0406326abc3f126a64ee075982d299 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Sun, 26 Jan 2025 20:18:31 +0100 Subject: [PATCH] feat(tasks): mark task buffers as clean when task exits --- src/buffer/Buffer.zig | 4 ++++ src/tui/editor.zig | 8 ++++++++ src/tui/mainview.zig | 8 ++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/buffer/Buffer.zig b/src/buffer/Buffer.zig index 12e8552..7761ee9 100644 --- a/src/buffer/Buffer.zig +++ b/src/buffer/Buffer.zig @@ -1317,6 +1317,10 @@ pub fn store_to_file_and_clean(self: *Self, file_path: []const u8) StoreToFileEr self.file_utf8_sanitized = false; } +pub fn mark_clean(self: *Self) void { + self.last_save = self.root; +} + pub fn is_dirty(self: *const Self) bool { return if (!self.file_exists) self.root.length() > 0 diff --git a/src/tui/editor.zig b/src/tui/editor.zig index 5fc89d5..f12c282 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -4724,6 +4724,14 @@ pub const Editor = struct { } pub const switch_case_meta = .{ .description = "Switch the case of selection or character at cursor" }; + pub fn forced_mark_clean(self: *Self, _: Context) Result { + if (self.buffer) |b| { + b.mark_clean(); + self.update_event() catch {}; + } + } + pub const forced_mark_clean_meta = .{ .description = "Force current file to be marked as clean" }; + pub fn toggle_eol_mode(self: *Self, _: Context) Result { if (self.buffer) |b| { b.file_eol_mode = switch (b.file_eol_mode) { diff --git a/src/tui/mainview.zig b/src/tui/mainview.zig index 24fe676..5d16b3e 100644 --- a/src/tui/mainview.zig +++ b/src/tui/mainview.zig @@ -759,8 +759,12 @@ const cmds = struct { var buffer_ref: usize = 0; if (!try ctx.args.match(.{tp.extract(&buffer_ref)})) return error.InvalidShellOutputCompleteArgument; - // TODO - _ = self; + const buffer = self.buffer_manager.buffer_from_ref(buffer_ref) orelse return; + if (self.get_active_editor()) |editor| if (editor.buffer) |eb| if (eb == buffer) { + editor.forced_mark_clean(.{}) catch {}; + return; + }; + buffer.mark_clean(); } pub const shell_execute_stream_output_complete_meta = .{ .arguments = &.{ .integer, .string } };