mirror of
https://github.com/folke/snacks.nvim
synced 2025-12-23 08:47:57 +00:00
fix(explorer): refresh git status on all tabs when needed. Closes #2348
This commit is contained in:
parent
235d99330b
commit
1472211f9c
2 changed files with 45 additions and 27 deletions
|
|
@ -59,44 +59,53 @@ function M.refresh()
|
|||
100,
|
||||
0,
|
||||
vim.schedule_wrap(function()
|
||||
local picker = Snacks.picker.get({ source = "explorer" })[1]
|
||||
if picker and not picker.closed and Tree:is_dirty(picker:cwd(), picker.opts) then
|
||||
if not picker.list.target then
|
||||
picker.list:set_target()
|
||||
local pickers = Snacks.picker.get({ source = "explorer", tab = false })
|
||||
for _, picker in ipairs(pickers) do
|
||||
if picker and not picker.closed and Tree:is_dirty(picker:cwd(), picker.opts) then
|
||||
if not picker.list.target then
|
||||
picker.list:set_target()
|
||||
end
|
||||
vim.schedule(function()
|
||||
picker:find()
|
||||
end)
|
||||
end
|
||||
vim.schedule(function()
|
||||
picker:find()
|
||||
end)
|
||||
end
|
||||
end)
|
||||
)
|
||||
end
|
||||
|
||||
---@param cwd string
|
||||
function M.watch(cwd)
|
||||
function M.watch()
|
||||
-- Track used watches
|
||||
local used = {} ---@type table<string, boolean>
|
||||
|
||||
-- Watch git index
|
||||
local root = Snacks.git.get_root(cwd)
|
||||
if root then
|
||||
used[root .. "/.git"] = true
|
||||
M.start(root .. "/.git", function(file)
|
||||
if vim.fs.basename(file) == "index" then
|
||||
Git.refresh(root)
|
||||
M.refresh()
|
||||
local pickers = Snacks.picker.get({ source = "explorer", tab = false })
|
||||
local cwds = {} ---@type table<string, boolean>
|
||||
for _, picker in ipairs(pickers) do
|
||||
cwds[picker:cwd()] = true
|
||||
end
|
||||
|
||||
for cwd in pairs(cwds) do
|
||||
-- Watch git index
|
||||
local root = Snacks.git.get_root(cwd)
|
||||
if root then
|
||||
used[root .. "/.git"] = true
|
||||
M.start(root .. "/.git", function(file)
|
||||
if vim.fs.basename(file) == "index" then
|
||||
Git.refresh(root)
|
||||
M.refresh()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- Watch open directories
|
||||
Tree:walk(Tree:find(cwd), function(node)
|
||||
if node.dir and node.open then
|
||||
used[node.path] = true
|
||||
M.start(node.path)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- Watch open directories
|
||||
Tree:walk(Tree:find(cwd), function(node)
|
||||
if node.dir and node.open then
|
||||
used[node.path] = true
|
||||
M.start(node.path)
|
||||
end
|
||||
end)
|
||||
|
||||
-- Stop unused watches
|
||||
for path in pairs(M._watches) do
|
||||
if not used[path] then
|
||||
|
|
|
|||
|
|
@ -50,7 +50,9 @@ function State.new(picker)
|
|||
if opts.watch then
|
||||
local on_close = picker.opts.on_close
|
||||
picker.opts.on_close = function(p)
|
||||
require("snacks.explorer.watch").abort()
|
||||
vim.schedule(function()
|
||||
require("snacks.explorer.watch").watch()
|
||||
end)
|
||||
if on_close then
|
||||
on_close(p)
|
||||
end
|
||||
|
|
@ -65,6 +67,13 @@ function State.new(picker)
|
|||
end
|
||||
end)
|
||||
|
||||
picker.list.win:on("TabEnter", function(_, ev)
|
||||
local p = ref()
|
||||
if p and p:on_current_tab() then
|
||||
Actions.update(p)
|
||||
end
|
||||
end)
|
||||
|
||||
picker.list.win:on("WinEnter", function(_, ev)
|
||||
local p = ref()
|
||||
if p then
|
||||
|
|
@ -137,7 +146,7 @@ end
|
|||
function State:setup(ctx)
|
||||
local opts = ctx.picker.opts --[[@as snacks.picker.explorer.Config]]
|
||||
if opts.watch then
|
||||
require("snacks.explorer.watch").watch(ctx.filter.cwd)
|
||||
require("snacks.explorer.watch").watch()
|
||||
end
|
||||
return not ctx.filter:is_empty()
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue