fix: find_node offset when hide_root_folder is true

fixes #843
This commit is contained in:
kiyan
2022-01-21 12:55:07 +01:00
parent da302ea3b1
commit 00807d7bd5

View File

@@ -85,12 +85,13 @@ end
-- get the node from the tree that matches the predicate -- get the node from the tree that matches the predicate
-- @param nodes list of node -- @param nodes list of node
-- @param fn function(node): boolean -- @param fn function(node): boolean
function M.find_node(nodes, fn) function M.find_node(_nodes, _fn)
local function iter(nodes, fn)
local i = 1 local i = 1
for _, node in ipairs(nodes) do for _, node in ipairs(nodes) do
if fn(node) then return node, i end if fn(node) then return node, i end
if node.open and #node.entries > 0 then if node.open and #node.entries > 0 then
local n, idx = M.find_node(node.entries, fn) local n, idx = iter(node.entries, fn)
i = i + idx i = i + idx
if n then return n, i end if n then return n, i end
else else
@@ -99,6 +100,10 @@ function M.find_node(nodes, fn)
end end
return nil, i return nil, i
end end
local node, i = iter(_nodes, _fn)
i = require'nvim-tree.view'.View.hide_root_folder and i - 1 or i
return node, i
end
---Create a shallow copy of a portion of a list. ---Create a shallow copy of a portion of a list.
---@param t table ---@param t table