From d4eb0d046c663509c90508c2e251deefa0e13f20 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Fri, 30 Jan 2026 13:22:47 +0100 Subject: [PATCH] refactor: fix completion updates --- src/tui/editor.zig | 7 +++++-- src/tui/mainview.zig | 4 ++-- src/tui/mode/overlay/completion_dropdown.zig | 1 + src/tui/mode/overlay/dropdown.zig | 1 + 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/tui/editor.zig b/src/tui/editor.zig index d045f42..5958fb7 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -6601,15 +6601,18 @@ pub const Editor = struct { self.completions_request = .done; } + var open_completions = self.completions.data.items.len > 0; const update_completion = "update_completion"; - if (command.get_id(update_completion)) |cmd_id| + if (command.get_id(update_completion)) |cmd_id| { try command.execute(cmd_id, update_completion, .{}); + open_completions = false; + } if (self.completions_refresh_pending) { self.completions_refresh_pending = false; try self.completion(.{}); } - return self.completions.data.items.len > 0; + return open_completions; } pub fn get_completion_replacement_selection(self: *Self, insert_: ?Selection, replace_: ?Selection) ?Selection { diff --git a/src/tui/mainview.zig b/src/tui/mainview.zig index 5f3b97a..e136006 100644 --- a/src/tui/mainview.zig +++ b/src/tui/mainview.zig @@ -1198,8 +1198,8 @@ const cmds = struct { var file_path_buf: [std.fs.max_path_bytes]u8 = undefined; file_path = project_manager.normalize_file_path(file_path, &file_path_buf); if (self.get_active_editor()) |editor| if (std.mem.eql(u8, file_path, editor.file_path orelse "")) { - const have_completions = try editor.add_completion_done(); - if (have_completions) { + const open_completions = try editor.add_completion_done(); + if (open_completions) { switch (tui.config().completion_style) { .palette => try tui.open_overlay(@import("mode/overlay/completion_palette.zig").Type), .dropdown => try tui.open_overlay(@import("mode/overlay/completion_dropdown.zig").Type), diff --git a/src/tui/mode/overlay/completion_dropdown.zig b/src/tui/mode/overlay/completion_dropdown.zig index 5807bf8..648dca8 100644 --- a/src/tui/mode/overlay/completion_dropdown.zig +++ b/src/tui/mode/overlay/completion_dropdown.zig @@ -137,6 +137,7 @@ fn update_query(self: *Type, cursor: ed.Cursor) error{OutOfMemory}!void { else => |e_| return e_, }; defer self.allocator.free(query); + self.update_query(query) catch return; tp.self_pid().send(.{ "cmd", "completion" }) catch |e| self.logger.err(module_name, e); return; } diff --git a/src/tui/mode/overlay/dropdown.zig b/src/tui/mode/overlay/dropdown.zig index 6fd7956..4db293a 100644 --- a/src/tui/mode/overlay/dropdown.zig +++ b/src/tui/mode/overlay/dropdown.zig @@ -267,6 +267,7 @@ pub fn Create(options: type) type { } pub fn update_query(self: *Self, query: []const u8) !void { + self.query.clearRetainingCapacity(); try self.query.appendSlice(self.allocator, query); return self.start_query(0); }