Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adding select_and_enter command #957

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading