From ed027b5f6d0052849192f94e5c38ddbcacc6cd29 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 23 Dec 2025 22:36:16 +0100 Subject: [PATCH 1/3] refactor: store trigger commands as strings Because command IDs are not stable across restarts. --- src/tui/editor.zig | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/tui/editor.zig b/src/tui/editor.zig index 0a22e87..8a88886 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -270,11 +270,16 @@ pub const TriggerSymbol = struct { pub fn cborEncode(self: @This(), writer: *std.Io.Writer) std.io.Writer.Error!void { try cbor.writeArrayHeader(writer, 2); try cbor.writeValue(writer, self.char); - try cbor.writeValue(writer, self.command); + try cbor.writeValue(writer, command.get_name(self.command)); } pub fn cborExtract(self: *@This(), iter: *[]const u8) cbor.Error!bool { - return try cbor.matchValue(iter, .{ cbor.extract(&self.char), cbor.extract(&self.command) }); + var command_name: []const u8 = undefined; + if (try cbor.matchValue(iter, .{ cbor.extract(&self.char), cbor.extract(&command_name) })) { + self.command = command.get_id(command_name) orelse command.ID_unknown; + return true; + } + return false; } }; @@ -496,8 +501,8 @@ pub const Editor = struct { try cbor.writeValue(writer, self.tab_width); try cbor.writeValue(writer, self.indent_mode); try cbor.writeValue(writer, self.syntax_no_render); - try cbor.writeValue(writer, self.insert_triggers); - try cbor.writeValue(writer, self.delete_triggers); + try cbor.writeValue(writer, self.insert_triggers.items); + try cbor.writeValue(writer, self.delete_triggers.items); if (self.find_history) |history| { try cbor.writeArrayHeader(writer, history.items.len); for (history.items) |item| @@ -519,6 +524,8 @@ pub const Editor = struct { var view_cbor: []const u8 = undefined; var cursels_cbor: []const u8 = undefined; var last_find_query: []const u8 = undefined; + var insert_triggers: []TriggerSymbol = undefined; + var delete_triggers: []TriggerSymbol = undefined; var find_history: []const u8 = undefined; if (!try cbor.matchValue(iter, .{ tp.extract(&file_path), @@ -528,13 +535,17 @@ pub const Editor = struct { tp.extract(&self.tab_width), tp.extract(&self.indent_mode), tp.extract(&self.syntax_no_render), - cbor.extractAlloc(&self.insert_triggers, self.allocator), - cbor.extractAlloc(&self.delete_triggers, self.allocator), + cbor.extractAlloc(&insert_triggers, self.allocator), + cbor.extractAlloc(&delete_triggers, self.allocator), tp.extract_cbor(&find_history), tp.extract_cbor(&view_cbor), tp.extract_cbor(&cursels_cbor), })) return error.RestoreStateMatch; + self.insert_triggers.deinit(self.allocator); + self.insert_triggers = .fromOwnedSlice(insert_triggers); + self.delete_triggers.deinit(self.allocator); + self.delete_triggers = .fromOwnedSlice(delete_triggers); self.refresh_tab_width(); if (op == .open_file) try self.open(file_path); From 96676c738a41e7a96f04b42c185a9f2a10be74f6 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 23 Dec 2025 22:36:56 +0100 Subject: [PATCH 2/3] refactor: prevent duplicate triggers --- src/tui/editor.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tui/editor.zig b/src/tui/editor.zig index 8a88886..5cfefd8 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -6240,6 +6240,7 @@ pub const Editor = struct { } pub fn add_symbol_trigger(self: *Self, char: u8, command_: command.ID, event: TriggerEvent) error{OutOfMemory}!void { + for (self.get_event_triggers(event).items) |item| if (item.char == char and item.command == command_) return; (try self.get_event_triggers(event).addOne(self.allocator)).* = .{ .char = char, .command = command_ }; } From 6fce29f8761a2b4187a114285bee4fece895f7f9 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 23 Dec 2025 22:37:08 +0100 Subject: [PATCH 3/3] refactor: ignore late palette_menu_cancel calls --- src/command.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/src/command.zig b/src/command.zig index ae41689..6991794 100644 --- a/src/command.zig +++ b/src/command.zig @@ -208,6 +208,7 @@ const suppressed_errors = std.StaticStringMap(void).initComptime(.{ .{ "enable_fast_scroll", void }, .{ "disable_fast_scroll", void }, .{ "clear_diagnostics", void }, + .{ "palette_menu_cancel", void }, }); pub fn executeName(name: []const u8, ctx: Context) tp.result {