mirror of
https://github.com/folke/snacks.nvim
synced 2025-12-23 08:47:57 +00:00
fix(win): ignore errors on destroy. Closes #2381
This commit is contained in:
parent
28ddbbe2be
commit
a8930bdb61
1 changed files with 12 additions and 4 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue