@@ -49,32 +49,11 @@ function trigger.activate_autocmds()
49
49
end ,
50
50
})
51
51
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
-
67
52
vim .api .nvim_create_autocmd ({ ' CursorMovedI' , ' InsertEnter' }, {
68
53
callback = function (ev )
69
54
-- characters added so let textchanged handle it
70
55
if last_char ~= ' ' then return end
71
56
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
-
78
57
local cursor_col = vim .api .nvim_win_get_cursor (0 )[2 ]
79
58
local char_under_cursor = vim .api .nvim_get_current_line ():sub (cursor_col , cursor_col )
80
59
local is_on_trigger = vim .tbl_contains (sources .get_trigger_characters (), char_under_cursor )
128
107
function trigger .show (opts )
129
108
opts = opts or {}
130
109
131
- -- update context
132
110
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
133
117
if trigger .context == nil then trigger .current_context_id = trigger .current_context_id + 1 end
134
118
trigger .context = {
135
119
id = trigger .current_context_id ,
0 commit comments