Skip to content

Commit

Permalink
fix: close input window when entering cmdline window (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Jun 2, 2023
1 parent f19cbd5 commit f16d758
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lua/dressing/input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,18 @@ local function confirm(text)
-- otherwise vim gets into a very weird and bad state. I was seeing text get
-- deleted from the buffer after the input window closes.
vim.defer_fn(function()
pcall(vim.api.nvim_win_close, ctx.winid, true)
local ok, err = pcall(vim.api.nvim_win_close, ctx.winid, true)
-- If we couldn't close the window because we're in the cmdline,
-- try again after WinLeave
if not ok and err and err:match("^E11:") then
local winid = ctx.winid
vim.api.nvim_create_autocmd("WinLeave", {
callback = vim.schedule_wrap(function()
pcall(vim.api.nvim_win_close, winid, true)
end),
once = true,
})
end
if text and history[#history] ~= text then
table.insert(history, text)
end
Expand Down
3 changes: 3 additions & 0 deletions lua/dressing/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ M._on_win_closed = function(winid)
end

M.schedule_wrap_before_vimenter = function(func)
if vim.g.is_test then
return func
end
return function(...)
if vim.v.vim_did_enter == 0 then
return vim.schedule_wrap(func)(...)
Expand Down
1 change: 1 addition & 0 deletions tests/minimal_init.lua
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vim.cmd([[set runtimepath+=.]])
vim.cmd([[runtime! plugin/plenary.vim]])
vim.g.is_test = true

0 comments on commit f16d758

Please sign in to comment.