Skip to content

Commit 9428983

Browse files
committed
fix: autocmd called in fast event
Closes #396
1 parent 56f7cb6 commit 9428983

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lua/blink/cmp/lib/event_emitter.lua

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ function event_emitter:emit(data)
2727
for _, callback in ipairs(self.listeners) do
2828
callback(data)
2929
end
30-
if self.autocmd then vim.api.nvim_exec_autocmds('User', { pattern = self.autocmd, modeline = false, data = data }) end
30+
if self.autocmd then
31+
require('blink.cmp.lib.utils').schedule_if_needed(
32+
vim.api.nvim_exec_autocmds('User', { pattern = self.autocmd, modeline = false, data = data })
33+
)
34+
end
3135
end
3236

3337
return event_emitter

lua/blink/cmp/lib/utils.lua

+8
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,12 @@ function utils.get_regex_around_cursor(range, regex, exclude_from_prefix_regex)
8383
return { start_col = start_col, length = length }
8484
end
8585

86+
function utils.schedule_if_needed(fn)
87+
if vim.in_fast_event() then
88+
vim.schedule(fn)
89+
else
90+
fn()
91+
end
92+
end
93+
8694
return utils

0 commit comments

Comments
 (0)