chore(iterators): create Iterator module and migrate iterators to use it (#1392)

This commit is contained in:
Kiyan
2022-07-04 14:13:14 +02:00
committed by GitHub
parent 70bdf496ea
commit f43b8af8f4
7 changed files with 177 additions and 154 deletions

View File

@@ -1,6 +1,7 @@
local renderer = require "nvim-tree.renderer"
local utils = require "nvim-tree.utils"
local core = require "nvim-tree.core"
local Iterator = require "nvim-tree.iterators.node-iterator"
local M = {}
@@ -9,34 +10,29 @@ function M.fn(keep_buffers)
return
end
local buffer_paths = {}
for _, buffer in ipairs(vim.api.nvim_list_bufs()) do
table.insert(buffer_paths, vim.api.nvim_buf_get_name(buffer))
end
local buffer_paths = vim.tbl_map(function(buffer)
return vim.api.nvim_buf_get_name(buffer)
end, vim.api.nvim_list_bufs())
local function iter(nodes)
for _, node in pairs(nodes) do
if node.open then
local new_open = false
if keep_buffers == true then
for _, buffer_path in ipairs(buffer_paths) do
local matches = utils.str_find(buffer_path, node.absolute_path)
if matches then
new_open = true
end
Iterator.builder(core.get_explorer().nodes)
:hidden()
:applier(function(node)
node.open = false
if keep_buffers == true then
for _, buffer_path in ipairs(buffer_paths) do
local matches = utils.str_find(buffer_path, node.absolute_path)
if matches then
node.open = true
return
end
end
node.open = new_open
end
if node.nodes then
iter(node.nodes)
end
end
end
end)
:recursor(function(n)
return n.nodes
end)
:iterate()
iter(core.get_explorer().nodes)
renderer.draw()
end