From 8c9146a1c5fcc6f945e39c3e40eae53f9764cd94 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Thu, 18 Dec 2025 22:30:48 +0100 Subject: [PATCH] fix: replace full completion item correctly in completion_dropdown --- src/tui/mode/overlay/completion_dropdown.zig | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/tui/mode/overlay/completion_dropdown.zig b/src/tui/mode/overlay/completion_dropdown.zig index 338a99d..1477348 100644 --- a/src/tui/mode/overlay/completion_dropdown.zig +++ b/src/tui/mode/overlay/completion_dropdown.zig @@ -108,8 +108,9 @@ pub fn update_query(self: *Type, query: []const u8) void { primary.selection = get_insert_selection(self, editor.get_primary().cursor); const b = editor.buf_for_update() catch return; const root_ = editor.insert(b.root, primary, query, b.allocator) catch return; - primary.selection = null; self.value.cursor = editor.get_primary().cursor; + if (self.value.replace) |*sel| sel.* = .{ .begin = sel.begin, .end = self.value.cursor }; + primary.selection = null; editor.update_buf(root_) catch {}; editor.clamp(); editor.need_render(); @@ -117,13 +118,12 @@ pub fn update_query(self: *Type, query: []const u8) void { } fn get_insert_selection(self: *Type, cursor: ed.Cursor) ed.Selection { - const begin = if (self.value.replace) |sel| - sel.begin + return if (self.value.replace) |sel| + sel else if (self.value.start.selection) |sel| - sel.begin + sel else - self.value.start.cursor; - return .{ .begin = begin, .end = cursor }; + .{ .begin = self.value.start.cursor, .end = cursor }; } pub fn clear_entries(self: *Type) void {