fix(cmp): use better cmp.confirm
This commit is contained in:
@ -36,4 +36,25 @@ function M.add_missing_snippet_docs(window)
|
||||
end
|
||||
end
|
||||
|
||||
-- This is a better implementation of `cmp.confirm`:
|
||||
-- * check if the completion menu is visible without waiting for running sources
|
||||
-- * create an undo point before confirming
|
||||
-- This function is both faster and more reliable.
|
||||
---@param opts? {select: boolean, behavior: cmp.ConfirmBehavior}
|
||||
function M.confirm(opts)
|
||||
local cmp = require("cmp")
|
||||
opts = vim.tbl_extend("force", {
|
||||
select = true,
|
||||
behavior = cmp.ConfirmBehavior.Insert,
|
||||
}, opts or {})
|
||||
return function(fallback)
|
||||
if cmp.core.view:visible() or vim.fn.pumvisible() == 1 then
|
||||
LazyVim.create_undo()
|
||||
if cmp.confirm(opts) then
|
||||
return
|
||||
end
|
||||
end
|
||||
return fallback()
|
||||
end
|
||||
end
|
||||
return M
|
||||
|
Reference in New Issue
Block a user