Skip to content

Commit 4883420

Browse files
committed
feat: ignore repeated call at cursor position in trigger
1 parent 41edb65 commit 4883420

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

lua/blink/cmp/trigger/completion.lua

+6-22
Original file line numberDiff line numberDiff line change
@@ -49,32 +49,11 @@ function trigger.activate_autocmds()
4949
end,
5050
})
5151

52-
-- hack: 'a' triggers both the InsertEnter and CursorMovedI event
53-
-- However, the cursor_col hasn't changed. When we're on a trigger character,
54-
-- this causes two show() calls, one with the trigger character and one without.
55-
-- To prevent this, we ignore the first CursorMovedI event when 'a' is pressed
56-
local ignore_next_cursor_moved = false
57-
vim.api.nvim_set_keymap('n', 'a', '', {
58-
callback = function()
59-
ignore_next_cursor_moved = true
60-
return 'a'
61-
end,
62-
expr = true,
63-
noremap = true,
64-
silent = true,
65-
})
66-
6752
vim.api.nvim_create_autocmd({ 'CursorMovedI', 'InsertEnter' }, {
6853
callback = function(ev)
6954
-- characters added so let textchanged handle it
7055
if last_char ~= '' then return end
7156

72-
-- ignore CursorMovedI event when flag is enabled
73-
if ev.event == 'CursorMovedI' and ignore_next_cursor_moved then
74-
ignore_next_cursor_moved = false
75-
return
76-
end
77-
7857
local cursor_col = vim.api.nvim_win_get_cursor(0)[2]
7958
local char_under_cursor = vim.api.nvim_get_current_line():sub(cursor_col, cursor_col)
8059
local is_on_trigger = vim.tbl_contains(sources.get_trigger_characters(), char_under_cursor)
@@ -128,8 +107,13 @@ end
128107
function trigger.show(opts)
129108
opts = opts or {}
130109

131-
-- update context
132110
local cursor = vim.api.nvim_win_get_cursor(0)
111+
-- already triggered at this position, ignore
112+
if trigger.context ~= nil and cursor[1] == trigger.context.cursor[1] and cursor[2] == trigger.context.cursor[2] then
113+
return
114+
end
115+
116+
-- update context
133117
if trigger.context == nil then trigger.current_context_id = trigger.current_context_id + 1 end
134118
trigger.context = {
135119
id = trigger.current_context_id,

0 commit comments

Comments
 (0)