refactor(renderer): extract folder builder

This commit is contained in:
kiyan 2022-04-23 11:22:28 +02:00
parent 018ba086d4
commit df41b0c586

View File

@ -188,19 +188,7 @@ local function build_file(node, padding, offset, git_hl, special)
index = index + 1
end
local function update_draw_data(tree, depth, markers)
local special = get_special_files_map()
for idx, node in ipairs(tree.nodes) do
local padding = _padding.get_padding(depth, idx, tree, node, markers)
local offset = string.len(padding)
if depth > 0 then
table.insert(hl, { "NvimTreeIndentMarker", index, 0, offset })
end
local git_hl = git.get_highlight(node)
if node.nodes then
local function build_folder(node, padding, offset, depth, git_hl, special, markers)
local has_children = #node.nodes ~= 0 or node.has_children
local icon = get_folder_icon(node.open, node.link_to ~= nil, has_children)
local git_icon = git.get_icons(node, index, offset, #icon, hl) or ""
@ -228,10 +216,26 @@ local function update_draw_data(tree, depth, markers)
index = index + 1
if node.open then
table.insert(lines, padding .. icon .. git_icon .. name .. (vim.g.nvim_tree_add_trailing == 1 and "/" or ""))
update_draw_data(node, depth + 2, markers)
M._update_draw_data(node, depth + 2, markers)
else
table.insert(lines, padding .. icon .. git_icon .. name .. (vim.g.nvim_tree_add_trailing == 1 and "/" or ""))
end
end
function M._update_draw_data(tree, depth, markers)
local special = get_special_files_map()
for idx, node in ipairs(tree.nodes) do
local padding = _padding.get_padding(depth, idx, tree, node, markers)
local offset = string.len(padding)
if depth > 0 then
table.insert(hl, { "NvimTreeIndentMarker", index, 0, offset })
end
local git_hl = git.get_highlight(node)
if node.nodes then
build_folder(node, padding, offset, depth, git_hl, special, markers)
elseif node.link_to then
build_symlink(node, padding, offset, git_hl)
else
@ -276,7 +280,7 @@ function M.draw()
_padding.reload_padding_function()
git.reload()
compute_header()
update_draw_data(core.get_explorer(), show_arrows and 2 or 0, {})
M._update_draw_data(core.get_explorer(), show_arrows and 2 or 0, {})
if view.is_help_ui() then
lines, hl = _help.compute_lines()