fix(explorer): reset main when entering another window. Closes #1587

This commit is contained in:
Folke Lemaitre 2025-10-21 16:27:14 +02:00
parent d358bf1755
commit a5d45d543e
No known key found for this signature in database
GPG key ID: 9B52594D560070AB
2 changed files with 16 additions and 4 deletions

View file

@ -18,8 +18,7 @@ function M.new(opts)
}, opts or {}) }, opts or {})
local self = setmetatable({}, M) local self = setmetatable({}, M)
self.opts = opts self.opts = opts
self.win = vim.api.nvim_get_current_win() self:update()
self.win = self:find()
return self return self
end end
@ -30,19 +29,25 @@ function M:get()
return self.win return self.win
end end
function M:update()
self.win = self:find()
end
---@param win number ---@param win number
function M:set(win) function M:set(win)
self.win = win self.win = win
end end
function M:find() ---@param extra? number[]
function M:find(extra)
local current = vim.api.nvim_get_current_win() local current = vim.api.nvim_get_current_win()
self.win = self.win or current
if self.opts.current then if self.opts.current then
return current return current
end end
local prev = vim.fn.win_getid(vim.fn.winnr("#")) local prev = vim.fn.win_getid(vim.fn.winnr("#"))
local non_float = 0 local non_float = 0
local wins = { self.win, current, prev } local wins = { current, self.win, prev }
local all = vim.api.nvim_tabpage_list_wins(0) local all = vim.api.nvim_tabpage_list_wins(0)
-- sort all by lastused of the win buffer -- sort all by lastused of the win buffer
table.sort(all, function(a, b) table.sort(all, function(a, b)

View file

@ -63,6 +63,13 @@ function State.new(picker)
end end
end) end)
picker.list.win:on("WinEnter", function(_, ev)
local p = ref()
if p then
p._main:update()
end
end)
picker.list.win:on("DirChanged", function(_, ev) picker.list.win:on("DirChanged", function(_, ev)
local p = ref() local p = ref()
if p then if p then