Skip to content

Commit 54cc521

Browse files
committed
fix(keymap): accept completion when only one item remains
The recent `show_and_insert_or_accept_single` command did not accept the item when the completion list was filtered down to exactly one candidate. This commit introduces immediate acceptance in that scenario. See: #2037 (comment)
1 parent c5dbc4b commit 54cc521

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lua/blink/cmp/init.lua

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,18 @@ end
100100
--- Select the first completion item if there are multiple candidates, or accept it if there is only one, after showing
101101
--- @param opts? blink.cmp.CompletionListSelectAndAcceptOpts
102102
function cmp.show_and_insert_or_accept_single(opts)
103+
local list = require('blink.cmp.completion.list')
104+
105+
-- If the candidate list has been filtered down to exactly one item, accept it.
106+
if #list.items == 1 then
107+
vim.schedule(function() list.accept({ index = 1, callback = opts and opts.callback }) end)
108+
return true
109+
end
110+
103111
return cmp.show_and_insert({
104112
callback = function()
105-
local list = require('blink.cmp.completion.list')
106113
if #list.items == 1 then
107-
list.accept({
108-
index = 1,
109-
callback = opts and opts.callback,
110-
})
114+
list.accept({ index = 1, callback = opts and opts.callback })
111115
elseif opts and opts.callback then
112116
opts.callback()
113117
end

0 commit comments

Comments
 (0)