perf(picker): fixed some issues with closed pickers not always being garbage collected

This commit is contained in:
Folke Lemaitre 2025-01-20 10:30:44 +01:00
parent b59f4ff477
commit eebf44a34e
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
7 changed files with 82 additions and 24 deletions

View file

@ -382,18 +382,23 @@ function M:close(opts)
for w, win in pairs(self.wins) do
if opts.wins == false then
win.opts = self.win_opts[w]
elseif win:valid() then
win:close()
else
win:destroy()
end
end
for _, win in pairs(self.box_wins) do
win:close()
win:destroy()
end
self.opts = nil
self.root = nil
self.wins = nil
self.box_wins = nil
self.win_opts = nil
end
--- Check if layout is valid (visible)
function M:valid()
return self.root:valid()
return not self.closed and self.root:valid()
end
--- Check if the window has been used in the layout
@ -402,6 +407,28 @@ function M:is_enabled(w)
return not self:is_hidden(w) and self.wins[w].enabled
end
function M:hide()
for _, win in ipairs(self:get_wins()) do
if win:valid() then
vim.api.nvim_win_set_config(win.win, { hide = true })
if win.backdrop and win.backdrop:valid() then
vim.api.nvim_win_set_config(win.backdrop.win, { hide = true })
end
end
end
end
function M:unhide()
for _, win in ipairs(self:get_wins()) do
if win:valid() then
vim.api.nvim_win_set_config(win.win, { hide = false })
if win.backdrop and win.backdrop:valid() then
vim.api.nvim_win_set_config(win.backdrop.win, { hide = false })
end
end
end
end
--- Show the layout
function M:show()
if self:valid() then