mirror of
https://github.com/folke/snacks.nvim
synced 2025-12-23 08:47:57 +00:00
fix(explorer): reset main when entering another window. Closes #1587
This commit is contained in:
parent
d358bf1755
commit
a5d45d543e
2 changed files with 16 additions and 4 deletions
|
|
@ -18,8 +18,7 @@ function M.new(opts)
|
|||
}, opts or {})
|
||||
local self = setmetatable({}, M)
|
||||
self.opts = opts
|
||||
self.win = vim.api.nvim_get_current_win()
|
||||
self.win = self:find()
|
||||
self:update()
|
||||
return self
|
||||
end
|
||||
|
||||
|
|
@ -30,19 +29,25 @@ function M:get()
|
|||
return self.win
|
||||
end
|
||||
|
||||
function M:update()
|
||||
self.win = self:find()
|
||||
end
|
||||
|
||||
---@param win number
|
||||
function M:set(win)
|
||||
self.win = win
|
||||
end
|
||||
|
||||
function M:find()
|
||||
---@param extra? number[]
|
||||
function M:find(extra)
|
||||
local current = vim.api.nvim_get_current_win()
|
||||
self.win = self.win or current
|
||||
if self.opts.current then
|
||||
return current
|
||||
end
|
||||
local prev = vim.fn.win_getid(vim.fn.winnr("#"))
|
||||
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)
|
||||
-- sort all by lastused of the win buffer
|
||||
table.sort(all, function(a, b)
|
||||
|
|
|
|||
|
|
@ -63,6 +63,13 @@ function State.new(picker)
|
|||
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)
|
||||
local p = ref()
|
||||
if p then
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue