Skip to content

Commit

Permalink
fix(input): close completion window more reliably
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Dec 5, 2021
1 parent fe8f0ff commit 7e6e962
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lua/dressing/input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@ local context = {
winid = nil,
}

local function close_completion_window()
if vim.fn.pumvisible() == 1 then
local escape_key = vim.api.nvim_replace_termcodes("<C-e>", true, false, true)
vim.api.nvim_feedkeys(escape_key, "n", true)
end
end

M.confirm = function(text)
if not context.on_confirm then
return
end
close_completion_window()
local ctx = context
context = {}
vim.api.nvim_win_close(ctx.winid, true)
Expand Down Expand Up @@ -145,7 +153,7 @@ setmetatable(M, {
bufnr,
"i",
"<Esc>",
":lua require('dressing.input').confirm()<CR>",
"<cmd>lua require('dressing.input').confirm()<CR>",
keyopts
)
vim.fn.prompt_setprompt(bufnr, prompt)
Expand Down Expand Up @@ -177,12 +185,7 @@ setmetatable(M, {
vim.api.nvim_feedkeys(opts.default, "n", false)
end

-- Close the completion menu if visible
if vim.fn.pumvisible() == 1 then
local escape_key = vim.api.nvim_replace_termcodes("<C-e>", true, false, true)
vim.api.nvim_feedkeys(escape_key, "n", true)
end

close_completion_window()
M.highlight()
end,
})
Expand Down

0 comments on commit 7e6e962

Please sign in to comment.