diff --git a/src/tui/editor.zig b/src/tui/editor.zig index 99e0482..cfb8890 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -4995,6 +4995,15 @@ pub const Editor = struct { _ = self.pop_tabstop(); } + pub fn get_last_trigger_char(self: *Self) ?u8 { + const root = self.buf_root() catch return null; + var cursor = self.get_primary().cursor; + cursor.move_left(root, self.metrics) catch return null; + const egc, _, _ = cursor.egc_at(root, self.metrics) catch return null; + const char = if (egc.len == 1) egc[0] else return null; + return if (self.is_event_trigger(char, .insert)) char else null; + } + fn is_completion_boundary_left(root: Buffer.Root, cursor: *const Cursor, metrics: Buffer.Metrics, triggers: []const TriggerSymbol) bool { if (cursor.col == 0) return true; var next = cursor.*; @@ -6576,6 +6585,11 @@ pub const Editor = struct { }; } + pub fn is_event_trigger(self: *Self, char: u8, event: TriggerEvent) bool { + for (self.get_event_triggers(event).items) |item| if (item.char == char) return true; + return false; + } + fn clear_event_triggers(self: *Self) void { self.insert_triggers.deinit(self.allocator); self.delete_triggers.deinit(self.allocator); diff --git a/src/tui/mode/overlay/completion_dropdown.zig b/src/tui/mode/overlay/completion_dropdown.zig index 4bb279d..94484ea 100644 --- a/src/tui/mode/overlay/completion_dropdown.zig +++ b/src/tui/mode/overlay/completion_dropdown.zig @@ -381,6 +381,9 @@ const cmds = struct { const Result = command.Result; pub fn update_completion(self: *Type, _: Ctx) Result { + if (tui.config().completion_trigger == .automatic and self.value.editor.get_last_trigger_char() == null) + return tp.self_pid().send(.{ "cmd", "palette_menu_cancel" }) catch |e| self.logger.err(module_name, e); + clear_entries(self); self.longest_hint = try load_entries(self); try update_query_text(self, self.value.editor.get_primary().cursor);