Multiple tree explorer #2713
|
I'd like to know if it is possible to provide explorer multiple path so that one tree is open for every path given. I'd also like to know if it is possible, using options, to add a node called "Favorites" where you could add files using a keybind + custom action. If it is not possible, can I implement my own version of explorer ? If yes, where do I start from ? Thanks for your help ! |
Replies: 5 comments 4 replies
|
Related: |
|
Thanks for the information ! I am looking into it and making good progress toward what i want. Thanks a lot ! I however, would also like to have a split side bar with explorer on top and symbols (trouble) on the bottom. Do you have any idea on how to achieve that ? Or should I ask on the Trouble github ? And finally, do you know if it is possible to allow folding of the root folders (nodes without parent) ? Is it something I have to change in the finder function or somewhere else ? Again thank you for your help and your time. |
|
My dumb ass found a way to toggle the root directory: snacks.nvim/lua/snacks/explorer/tree.lua Line 237 in fe7cfe9 -- ...
local top = Tree:find(dir)
local top_open = top.open
local last = {} ---@type table<snacks.picker.explorer.Node, snacks.picker.explorer.Item>
Tree:get(dir, function(node)
if node == top then
node.open = top_open
end
if node ~= top and not top_open then
return
end
-- ... |
|
Sorry for my delayed response, I wanted to finish another project before getting back on it. I tried your solution and it worked ! However, I now have more questions. I tried to look into I have difficulties understanding what part of snacks does these functions. Could you point me towards the files/functions that will help me correct this ? Regarding the foldable root directories, I am trying to add an option to choose if they should be by default open or closed. The solution is probably simple but I have difficulties understanding some things, like when does the Anyway, thanks a lot for your time and advices. |
|
It is the best you can get. Some limitations come from the picker using a single ---@module 'snacks'
local Tree = require("snacks.explorer.tree")
local tree_get = Tree.get
Tree.get = function(self, cwd, cb, opts)
local cwd_node = Tree:find(cwd)
local cwd_open = cwd_node.open
tree_get(self, cwd, function(node)
if node.path == cwd_node.path then
node.open = cwd_open
end
if node.path ~= cwd_node.path and not cwd_open then
return
end
cb(node)
end, opts)
end
local cache_open = {}
local tree_toggle = function(path, open)
if open == false or open == nil then
Tree:close(path)
else
Tree:open(path)
end
end
return {
"folke/snacks.nvim",
lazy = false,
keys = {
-- stylua: ignore
{ "<Leader>e", function() Snacks.picker.explorer() end, desc = "Open explorer" },
},
---@type snacks.Config
opts = {
picker = {
sources = {
explorer = {
dirs = { "/home", "/home/clover" },
finder = function(opts, ctx)
local find = require("snacks.picker.source.explorer").explorer(opts, ctx)
local dirs = opts.dirs or { ctx:cwd() } ---@diagnostic disable-line
return function(cb)
for _, cwd in ipairs(dirs) do
if not ctx.picker.shown then
tree_toggle(cwd, cache_open[cwd])
end
cache_open[cwd] = Tree:node(cwd).open
ctx.picker:set_cwd(cwd)
find(cb)
end
end
end,
},
},
},
},
} |
It is possible, but not via option, so you need to override finder function (see related.1):
snacks.nvim/lua/snacks/picker/config/sources.lua
Lines 50 to 51 in fe7cfe9
snacks.nvim/lua/snacks/picker/source/explorer.lua
Lines 190 to 264 in fe7cfe9