Skip to content

Commit

Permalink
fix: fire cursor moved when jumping between tab stops in a snippet
Browse files Browse the repository at this point in the history
Closes #545
  • Loading branch information
Saghen committed Dec 17, 2024
1 parent 7a04612 commit 1e4808e
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lua/blink/cmp/lib/buffer_events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,30 @@ function buffer_events:listen(opts)
end,
})

vim.api.nvim_create_autocmd({ 'CursorMovedI', 'InsertEnter' }, {
vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI', 'InsertEnter' }, {
callback = function(ev)
local is_ignored = ev.event == 'CursorMovedI' and self.ignore_next_cursor_moved
if ev.event == 'CursorMovedI' then self.ignore_next_cursor_moved = false end
-- only fire a CursorMoved event (notable not CursorMovedI) when jumping between tab stops in a snippet
-- and we're currently showing
if
ev.event == 'CursorMoved'
and (vim.api.nvim_get_mode().mode ~= 'v' or not self.has_context())
and snippet.active()
then
return
end

local is_cursor_moved = ev.event == 'CursorMoved' or ev.event == 'CursorMovedI'

local is_ignored = is_cursor_moved and self.ignore_next_cursor_moved
if is_cursor_moved then self.ignore_next_cursor_moved = false end

-- characters added so let textchanged handle it
if last_char ~= '' then return end

if not require('blink.cmp.config').enabled() then return end
if not self.show_in_snippet and not self.has_context() and snippet.active() then return end

local event = ev.event == 'CursorMovedI' and 'CursorMoved' or ev.event
opts.on_cursor_moved(event, is_ignored)
opts.on_cursor_moved(is_cursor_moved and 'CursorMoved' or ev.event, is_ignored)
end,
})

Expand Down

0 comments on commit 1e4808e

Please sign in to comment.