Skip to content

Commit

Permalink
feat: select_and_accept keymap
Browse files Browse the repository at this point in the history
closes #118
  • Loading branch information
Saghen committed Oct 16, 2024
1 parent 2f9f167 commit 6394508
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ MiniDeps.add({
show = '<C-space>',
hide = '<C-e>',
accept = '<Tab>',
select_and_accept = {},
select_prev = { '<Up>', '<C-p>' },
select_next = { '<Down>', '<C-n>' },

Expand Down
12 changes: 12 additions & 0 deletions lua/blink/cmp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ cmp.accept = function()
return true
end

cmp.select_and_accept = function()
if not cmp.windows.autocomplete.win:is_open() then return end

vim.schedule(function()
-- select an item if none is selected
if not cmp.windows.autocomplete.get_selected_item() then cmp.windows.autocomplete.select_next() end
local item = cmp.windows.autocomplete.get_selected_item()
if item ~= nil then require('blink.cmp.accept')(item) end
end)
return true
end

cmp.select_prev = function()
if not cmp.windows.autocomplete.win:is_open() then
cmp.show()
Expand Down
1 change: 1 addition & 0 deletions lua/blink/cmp/keymap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local insert_commands = {
'show',
'hide',
'accept',
'select_and_accept',
'select_prev',
'select_next',
'show_documentation',
Expand Down

0 comments on commit 6394508

Please sign in to comment.