fix(win): ignore errors on destroy. Closes #2381

This commit is contained in:
Folke Lemaitre 2025-10-29 14:02:16 +01:00
parent 28ddbbe2be
commit a8930bdb61
No known key found for this signature in database
GPG key ID: 9B52594D560070AB

View file

@ -516,7 +516,9 @@ function M:scroll(up)
end
function M:destroy()
self:close()
pcall(function()
self:close()
end)
self.events = {}
self.keys = {}
self.meta = {}
@ -542,6 +544,7 @@ function M:close(opts)
end
local close = function()
local errors = {} ---@type string[]
if win and vim.api.nvim_win_is_valid(win) then
local ok, err = pcall(vim.api.nvim_win_close, win, true)
if not ok and (err and err:find("E444")) then
@ -549,19 +552,24 @@ function M:close(opts)
vim.cmd("silent! vsplit")
pcall(vim.api.nvim_win_close, win, true)
elseif not ok then
error(err)
errors[#errors + 1] = err
end
end
if buf and vim.api.nvim_buf_is_valid(buf) then
vim.api.nvim_buf_delete(buf, { force = true })
local ok, err = pcall(vim.api.nvim_buf_delete, buf, { force = true })
errors[#errors + 1] = not ok and err or nil
end
if scratch_buf and vim.api.nvim_buf_is_valid(scratch_buf) then
vim.api.nvim_buf_delete(scratch_buf, { force = true })
local ok, err = pcall(vim.api.nvim_buf_delete, scratch_buf, { force = true })
errors[#errors + 1] = not ok and err or nil
end
if self.augroup then
pcall(vim.api.nvim_del_augroup_by_id, self.augroup)
self.augroup = nil
end
if #errors > 0 then
error(table.concat(errors, "\n"))
end
end
local retries = 0
local try_close ---@type fun()