fix(picker): close picker when layout closes. Closes #2365

This commit is contained in:
Folke Lemaitre 2025-10-31 23:19:58 +01:00
parent 143e9b58c7
commit 779746f9a8
No known key found for this signature in database
GPG key ID: 9B52594D560070AB
2 changed files with 8 additions and 0 deletions

View file

@ -33,6 +33,7 @@ M.meta = {
---@field hidden? string[] list of windows that will be excluded from the layout (but can be toggled)
---@field on_update? fun(layout: snacks.layout)
---@field on_update_pre? fun(layout: snacks.layout)
---@field on_close? fun(layout: snacks.layout)
local defaults = {
layout = {
width = 0.6,
@ -523,6 +524,9 @@ function M:close(opts)
win:destroy()
end
vim.schedule(function()
if self.opts.on_close then
self.opts.on_close(self)
end
self.opts = nil
self.root = nil
self.wins = nil

View file

@ -245,6 +245,9 @@ function M:init_layout(layout)
preview = self.preview.win,
},
hidden = layout.hidden,
on_close = function()
self:close()
end,
on_update = function()
self.preview:refresh(self)
self.input:update()
@ -365,6 +368,7 @@ function M:set_layout(layout)
)
end
self.list.reverse = layout.reverse
self.layout.opts.on_close = nil -- prevent closing the picker when changing layout
self.layout:close({ wins = false })
self:init_layout(layout)
self.layout:show()