fix(explorer): check that picker is still open

This commit is contained in:
Folke Lemaitre 2025-02-04 18:02:06 +01:00
parent a6bb63fa09
commit 50fa1be38e
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -34,7 +34,11 @@ function State.new(picker)
local self = setmetatable({}, State) local self = setmetatable({}, State)
local opts = picker.opts --[[@as snacks.picker.explorer.Config]] local opts = picker.opts --[[@as snacks.picker.explorer.Config]]
local ref = picker:ref() local r = picker:ref()
local function ref()
local v = r.value
return v and not v.closed and v or nil
end
local buf = vim.api.nvim_win_get_buf(picker.main) local buf = vim.api.nvim_win_get_buf(picker.main)
local buf_file = vim.fs.normalize(vim.api.nvim_buf_get_name(buf)) local buf_file = vim.fs.normalize(vim.api.nvim_buf_get_name(buf))
@ -58,11 +62,10 @@ function State.new(picker)
picker.list.win:on("BufWritePost", function(_, ev) picker.list.win:on("BufWritePost", function(_, ev)
local p = ref() local p = ref()
if not p then if p then
return true Tree:refresh(ev.file)
Actions.update(p)
end end
Tree:refresh(ev.file)
Actions.update(p)
end) end)
picker.list.win:on("DirChanged", function(_, ev) picker.list.win:on("DirChanged", function(_, ev)
@ -81,7 +84,7 @@ function State.new(picker)
return return
end end
local p = ref() local p = ref()
if not p or p:is_focused() or not p:on_current_tab() then if not p or p:is_focused() or not p:on_current_tab() or p.closed then
return return
end end
local win = vim.api.nvim_get_current_win() local win = vim.api.nvim_get_current_win()