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 {})
|
}, 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)
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue