fix(#1406): allow nvim-tree.renderer.icons.show.folder_arrow

* fix(#1406): allow nvim-tree.renderer.icons.show.folder_arrow when not folder

* fix(#1406): allow nvim-tree.renderer.icons.show.folder_arrow when indent markers enabled

* fix(builder): highlight first iteration for arrow column

* fix stylua

Co-authored-by: kiyan <yazdani.kiyan@protonmail.com>
This commit is contained in:
Alexander Courtis
2022-07-10 12:14:18 +10:00
committed by GitHub
parent 95c57e034a
commit fd562ede63
5 changed files with 33 additions and 37 deletions

View File

@@ -10,7 +10,7 @@ Builder.__index = Builder
function Builder.new(root_cwd)
return setmetatable({
index = 0,
depth = nil,
depth = 0,
highlights = {},
lines = {},
markers = {},
@@ -19,11 +19,6 @@ function Builder.new(root_cwd)
}, Builder)
end
function Builder:configure_initial_depth(show_arrows)
self.depth = show_arrows and 2 or 0
return self
end
function Builder:configure_root_modifier(root_folder_modifier)
self.root_folder_modifier = root_folder_modifier or ":~"
return self
@@ -232,7 +227,7 @@ end
function Builder:_build_line(node, idx, num_children)
local padding = pad.get_padding(self.depth, idx, num_children, node, self.markers)
if self.depth > 0 then
if string.len(padding) > 0 then
self:_insert_highlight("NvimTreeIndentMarker", 0, string.len(padding))
end

View File

@@ -1,21 +1,8 @@
local M = {}
function M.get_padding(depth)
return string.rep(" ", depth)
end
local function get_padding_arrows()
return function(depth, _, _, node)
if node.nodes then
local icon = M.config.icons.glyphs.folder[node.open and "arrow_open" or "arrow_closed"]
return string.rep(" ", depth - 2) .. icon .. " "
end
return string.rep(" ", depth)
end
end
local function get_padding_indent_markers(depth, idx, nodes_number, _, markers)
local function get_padding_indent_markers(depth, idx, nodes_number, markers)
local padding = ""
if depth ~= 0 then
local rdepth = depth / 2
markers[rdepth] = idx ~= nodes_number
@@ -34,14 +21,30 @@ local function get_padding_indent_markers(depth, idx, nodes_number, _, markers)
return padding
end
function M.reload_padding_function()
if M.config.icons.show.folder and M.config.icons.show.folder_arrow then
M.get_padding = get_padding_arrows()
local function get_padding_arrows(node, indent)
if node.nodes then
return M.config.icons.glyphs.folder[node.open and "arrow_open" or "arrow_closed"] .. " "
elseif indent then
return " "
else
return ""
end
end
function M.get_padding(depth, idx, nodes_number, node, markers)
local padding = ""
if M.config.indent_markers.enable then
M.get_padding = get_padding_indent_markers
padding = padding .. get_padding_indent_markers(depth, idx, nodes_number, markers)
else
padding = padding .. string.rep(" ", depth)
end
if M.config.icons.show.folder_arrow then
padding = padding .. get_padding_arrows(node, not M.config.indent_markers.enable)
end
return padding
end
function M.setup(opts)

View File

@@ -40,10 +40,6 @@ function M.render_hl(bufnr, hl)
end
end
local function should_show_arrows()
return not M.config.indent_markers.enable and M.config.icons.show.folder and M.config.icons.show.folder_arrow
end
local picture_map = {
jpg = true,
jpeg = true,
@@ -60,7 +56,6 @@ function M.draw()
local ps = log.profile_start "draw"
local cursor = api.nvim_win_get_cursor(view.get_winnr())
_padding.reload_padding_function()
icon_component.reset_config()
local lines, hl
@@ -69,7 +64,6 @@ function M.draw()
lines, hl = help.compute_lines()
else
lines, hl, signs = Builder.new(core.get_cwd())
:configure_initial_depth(should_show_arrows())
:configure_root_modifier(M.config.root_folder_modifier)
:configure_trailing_slash(M.config.add_trailing)
:configure_special_files(M.config.special_files)