From c75990f46fe4fc00d1afb391d57ced83c8268b2e Mon Sep 17 00:00:00 2001 From: Marco Caceffo Date: Wed, 8 Jan 2025 21:36:04 +0100 Subject: [PATCH] select_and_enter --- lua/blink/cmp/init.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lua/blink/cmp/init.lua b/lua/blink/cmp/init.lua index deb91160..e76f2550 100644 --- a/lua/blink/cmp/init.lua +++ b/lua/blink/cmp/init.lua @@ -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('', 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)