Skip to content

Commit 6394508

Browse files
committed
feat: select_and_accept keymap
closes #118
1 parent 2f9f167 commit 6394508

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ MiniDeps.add({
139139
show = '<C-space>',
140140
hide = '<C-e>',
141141
accept = '<Tab>',
142+
select_and_accept = {},
142143
select_prev = { '<Up>', '<C-p>' },
143144
select_next = { '<Down>', '<C-n>' },
144145

lua/blink/cmp/init.lua

+12
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ cmp.accept = function()
151151
return true
152152
end
153153

154+
cmp.select_and_accept = function()
155+
if not cmp.windows.autocomplete.win:is_open() then return end
156+
157+
vim.schedule(function()
158+
-- select an item if none is selected
159+
if not cmp.windows.autocomplete.get_selected_item() then cmp.windows.autocomplete.select_next() end
160+
local item = cmp.windows.autocomplete.get_selected_item()
161+
if item ~= nil then require('blink.cmp.accept')(item) end
162+
end)
163+
return true
164+
end
165+
154166
cmp.select_prev = function()
155167
if not cmp.windows.autocomplete.win:is_open() then
156168
cmp.show()

lua/blink/cmp/keymap.lua

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ local insert_commands = {
55
'show',
66
'hide',
77
'accept',
8+
'select_and_accept',
89
'select_prev',
910
'select_next',
1011
'show_documentation',

0 commit comments

Comments
 (0)