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:
parent
95c57e034a
commit
fd562ede63
@ -679,8 +679,8 @@ UI rendering setup
|
||||
Type: `boolean`, Default: `true`
|
||||
|
||||
*nvim-tree.renderer.icons.show.folder_arrow*
|
||||
Show a small arrow before the folder icon.
|
||||
Requires |renderer.icons.show.folder| `= true` and |renderer.indent_markers.enable| `= false`
|
||||
Show a small arrow before the folder node. Arrow will be a part of the
|
||||
node when using |renderer.indent_markers|.
|
||||
Type: `boolean`, Default: `true`
|
||||
|
||||
*nvim-tree.renderer.icons.show.git*
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -4,6 +4,12 @@ local M = {}
|
||||
|
||||
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 = {
|
||||
adaptive_size = false,
|
||||
centralize_selection = false,
|
||||
@ -29,9 +35,7 @@ M.View = {
|
||||
"EndOfBuffer:NvimTreeEndOfBuffer",
|
||||
"Normal:NvimTreeNormal",
|
||||
"CursorLine:NvimTreeCursorLine",
|
||||
-- #1221 WinSeparator not present in nvim 0.6.1 and some builds of 0.7.0
|
||||
pcall(vim.cmd, "silent hi WinSeparator") and "WinSeparator:NvimTreeWinSeparator"
|
||||
or "VertSplit:NvimTreeWinSeparator",
|
||||
get_win_sep_hl(),
|
||||
"StatusLine:NvimTreeStatusLine",
|
||||
"StatusLineNC:NvimTreeStatuslineNC",
|
||||
"SignColumn:NvimTreeSignColumn",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user