feat(live-filter): add ability to live filter out nodes in the tree (#1056)
This commit is contained in:
@@ -103,23 +103,26 @@ function M.find_node(nodes, fn)
|
||||
local function iter(nodes_, fn_)
|
||||
local i = 1
|
||||
for _, node in ipairs(nodes_) do
|
||||
if fn_(node) then
|
||||
return node, i
|
||||
end
|
||||
if node.open and #node.nodes > 0 then
|
||||
local n, idx = iter(node.nodes, fn_)
|
||||
i = i + idx
|
||||
if n then
|
||||
return n, i
|
||||
if not node.hidden then
|
||||
if fn_(node) then
|
||||
return node, i
|
||||
end
|
||||
if node.open and #node.nodes > 0 then
|
||||
local n, idx = iter(node.nodes, fn_)
|
||||
i = i + idx
|
||||
if n then
|
||||
return n, i
|
||||
end
|
||||
else
|
||||
i = i + 1
|
||||
end
|
||||
else
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
return nil, i
|
||||
end
|
||||
local node, i = iter(nodes, fn)
|
||||
i = require("nvim-tree.view").View.hide_root_folder and i - 1 or i
|
||||
i = require("nvim-tree.view").is_root_folder_visible() and i or i - 1
|
||||
i = require("nvim-tree.live-filter").filter and i + 1 or i
|
||||
return node, i
|
||||
end
|
||||
|
||||
@@ -132,12 +135,14 @@ function M.get_nodes_by_line(nodes_all, line_start)
|
||||
local line = line_start
|
||||
local function iter(nodes)
|
||||
for _, node in ipairs(nodes) do
|
||||
nodes_by_line[line] = node
|
||||
line = line + 1
|
||||
if node.open == true then
|
||||
local child = iter(node.nodes)
|
||||
if child ~= nil then
|
||||
return child
|
||||
if not node.hidden then
|
||||
nodes_by_line[line] = node
|
||||
line = line + 1
|
||||
if node.open == true then
|
||||
local child = iter(node.nodes)
|
||||
if child ~= nil then
|
||||
return child
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user