Skip to content

Commit

Permalink
select_and_enter
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosktsz committed Jan 8, 2025
1 parent a993bd8 commit c75990f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lua/blink/cmp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,24 @@ function cmp.select_and_accept(opts)
return true
end

--- Select the first completion item, if there's no selection, and enter
--- @param opts? blink.cmp.CompletionListSelectAndAcceptOpts
function cmp.select_and_enter(opts)
if not cmp.is_visible() then return end

local completion_list = require('blink.cmp.completion.list')
vim.schedule(function()
completion_list.accept({
index = completion_list.selected_item_idx or 1,
callback = function()
if opts and opts.callback then opts.callback() end
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<CR>', true, false, true), 'n', false)
end,
})
end)
return true
end

--- Select the previous completion item
--- @param opts? blink.cmp.CompletionListSelectOpts
function cmp.select_prev(opts)
Expand Down

0 comments on commit c75990f

Please sign in to comment.