mirror of
https://github.com/folke/snacks.nvim
synced 2025-12-23 08:47:57 +00:00
fix(explorer): do reveal in on_show if explorer is not open yet. Closes #2388
Some checks are pending
CI / ci (push) Waiting to run
Some checks are pending
CI / ci (push) Waiting to run
This commit is contained in:
parent
79fb03dc86
commit
ba529d4f5d
1 changed files with 18 additions and 9 deletions
|
|
@ -83,18 +83,27 @@ function M.reveal(opts)
|
|||
local Tree = require("snacks.explorer.tree")
|
||||
opts = opts or {}
|
||||
local file = svim.fs.normalize(opts.file or vim.api.nvim_buf_get_name(opts.buf or 0))
|
||||
local explorer = Snacks.picker.get({ source = "explorer" })[1] or M.open()
|
||||
local cwd = explorer:cwd()
|
||||
if not Tree:in_cwd(cwd, file) then
|
||||
for parent in vim.fs.parents(file) do
|
||||
if Tree:in_cwd(parent, cwd) then
|
||||
explorer:set_cwd(parent)
|
||||
break
|
||||
local explorer = Snacks.picker.get({ source = "explorer" })[1]
|
||||
|
||||
local function reveal()
|
||||
local cwd = explorer:cwd()
|
||||
if not Tree:in_cwd(cwd, file) then
|
||||
for parent in vim.fs.parents(file) do
|
||||
if Tree:in_cwd(parent, cwd) then
|
||||
explorer:set_cwd(parent)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
Tree:open(file)
|
||||
Actions.update(explorer, { target = file, refresh = true })
|
||||
end
|
||||
|
||||
if explorer then
|
||||
reveal()
|
||||
else
|
||||
explorer = M.open({ on_show = reveal })
|
||||
end
|
||||
Tree:open(file)
|
||||
Actions.update(explorer, { target = file, refresh = true })
|
||||
return explorer
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue