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 83b5662
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lua/blink/cmp/config/keymap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
--- | 'cancel' Cancel the current completion, undoing the preview from auto_insert
--- | 'accept' Accept the current completion item
--- | 'select_and_accept' Select the first completion item, if there's no selection, and accept
--- | 'select_and_enter' Select the first completion item, if there's no selection, and enter
--- | 'select_prev' Select the previous completion item
--- | 'select_next' Select the next completion item
--- | 'show_documentation' Show the documentation window
Expand Down Expand Up @@ -129,6 +130,7 @@ function keymap.validate(config)
'cancel',
'accept',
'select_and_accept',
'select_and_enter',
'select_prev',
'select_next',
'show_documentation',
Expand Down
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 83b5662

Please sign in to comment.