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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 37 deletions

View File

@ -679,8 +679,8 @@ UI rendering setup
Type: `boolean`, Default: `true` Type: `boolean`, Default: `true`
*nvim-tree.renderer.icons.show.folder_arrow* *nvim-tree.renderer.icons.show.folder_arrow*
Show a small arrow before the folder icon. Show a small arrow before the folder node. Arrow will be a part of the
Requires |renderer.icons.show.folder| `= true` and |renderer.indent_markers.enable| `= false` node when using |renderer.indent_markers|.
Type: `boolean`, Default: `true` Type: `boolean`, Default: `true`
*nvim-tree.renderer.icons.show.git* *nvim-tree.renderer.icons.show.git*

View File

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

View File

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

View File

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

View File

@ -4,6 +4,12 @@ local M = {}
local events = require "nvim-tree.events" local events = require "nvim-tree.events"
local function get_win_sep_hl()
-- #1221 WinSeparator not present in nvim 0.6.1 and some builds of 0.7.0
local has_win_sep = pcall(vim.cmd, "silent hi WinSeparator")
return has_win_sep and "WinSeparator:NvimTreeWinSeparator" or "VertSplit:NvimTreeWinSeparator"
end
M.View = { M.View = {
adaptive_size = false, adaptive_size = false,
centralize_selection = false, centralize_selection = false,
@ -29,9 +35,7 @@ M.View = {
"EndOfBuffer:NvimTreeEndOfBuffer", "EndOfBuffer:NvimTreeEndOfBuffer",
"Normal:NvimTreeNormal", "Normal:NvimTreeNormal",
"CursorLine:NvimTreeCursorLine", "CursorLine:NvimTreeCursorLine",
-- #1221 WinSeparator not present in nvim 0.6.1 and some builds of 0.7.0 get_win_sep_hl(),
pcall(vim.cmd, "silent hi WinSeparator") and "WinSeparator:NvimTreeWinSeparator"
or "VertSplit:NvimTreeWinSeparator",
"StatusLine:NvimTreeStatusLine", "StatusLine:NvimTreeStatusLine",
"StatusLineNC:NvimTreeStatuslineNC", "StatusLineNC:NvimTreeStatuslineNC",
"SignColumn:NvimTreeSignColumn", "SignColumn:NvimTreeSignColumn",