chore(iterators): create Iterator module and migrate iterators to use it (#1392)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
local core = require "nvim-tree.core"
|
||||
local renderer = require "nvim-tree.renderer"
|
||||
local utils = require "nvim-tree.utils"
|
||||
local Iterator = require "nvim-tree.iterators.node-iterator"
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -20,34 +21,38 @@ local function expand(node)
|
||||
end
|
||||
end
|
||||
|
||||
local function should_expand(expansion_count, node)
|
||||
local should_halt = expansion_count >= M.MAX_FOLDER_DISCOVERY
|
||||
local should_exclude = M.EXCLUDE[node.name]
|
||||
return not should_halt and node.nodes and not node.open and not should_exclude
|
||||
end
|
||||
|
||||
local function gen_iterator()
|
||||
local expansion_count = 0
|
||||
|
||||
local function iterate(parent)
|
||||
if expansion_count >= M.MAX_FOLDER_DISCOVERY then
|
||||
return true
|
||||
end
|
||||
|
||||
return function(parent)
|
||||
if parent.parent and parent.nodes and not parent.open then
|
||||
expansion_count = expansion_count + 1
|
||||
expand(parent)
|
||||
end
|
||||
|
||||
for _, node in pairs(parent.nodes) do
|
||||
if node.nodes and not node.open and not M.EXCLUDE[node.name] then
|
||||
expansion_count = expansion_count + 1
|
||||
expand(node)
|
||||
end
|
||||
|
||||
if node.open then
|
||||
if iterate(node) then
|
||||
return true
|
||||
Iterator.builder(parent.nodes)
|
||||
:hidden()
|
||||
:applier(function(node)
|
||||
if should_expand(expansion_count, node) then
|
||||
expansion_count = expansion_count + 1
|
||||
expand(node)
|
||||
end
|
||||
end
|
||||
end)
|
||||
:recursor(function(node)
|
||||
return expansion_count < M.MAX_FOLDER_DISCOVERY and node.open and node.nodes
|
||||
end)
|
||||
:iterate()
|
||||
|
||||
if expansion_count >= M.MAX_FOLDER_DISCOVERY then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return iterate
|
||||
end
|
||||
|
||||
function M.fn(base_node)
|
||||
|
||||
Reference in New Issue
Block a user