Skip to content

Commit fd562ed

Browse files
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>
1 parent 95c57e0 commit fd562ed

File tree

5 files changed

+33
-37
lines changed

5 files changed

+33
-37
lines changed

doc/nvim-tree-lua.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,8 +679,8 @@ UI rendering setup
679679
Type: `boolean`, Default: `true`
680680

681681
*nvim-tree.renderer.icons.show.folder_arrow*
682-
Show a small arrow before the folder icon.
683-
Requires |renderer.icons.show.folder| `= true` and |renderer.indent_markers.enable| `= false`
682+
Show a small arrow before the folder node. Arrow will be a part of the
683+
node when using |renderer.indent_markers|.
684684
Type: `boolean`, Default: `true`
685685

686686
*nvim-tree.renderer.icons.show.git*

lua/nvim-tree/renderer/builder.lua

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Builder.__index = Builder
1010
function Builder.new(root_cwd)
1111
return setmetatable({
1212
index = 0,
13-
depth = nil,
13+
depth = 0,
1414
highlights = {},
1515
lines = {},
1616
markers = {},
@@ -19,11 +19,6 @@ function Builder.new(root_cwd)
1919
}, Builder)
2020
end
2121

22-
function Builder:configure_initial_depth(show_arrows)
23-
self.depth = show_arrows and 2 or 0
24-
return self
25-
end
26-
2722
function Builder:configure_root_modifier(root_folder_modifier)
2823
self.root_folder_modifier = root_folder_modifier or ":~"
2924
return self
@@ -232,7 +227,7 @@ end
232227
function Builder:_build_line(node, idx, num_children)
233228
local padding = pad.get_padding(self.depth, idx, num_children, node, self.markers)
234229

235-
if self.depth > 0 then
230+
if string.len(padding) > 0 then
236231
self:_insert_highlight("NvimTreeIndentMarker", 0, string.len(padding))
237232
end
238233

lua/nvim-tree/renderer/components/padding.lua

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
11
local M = {}
22

3-
function M.get_padding(depth)
4-
return string.rep(" ", depth)
5-
end
6-
7-
local function get_padding_arrows()
8-
return function(depth, _, _, node)
9-
if node.nodes then
10-
local icon = M.config.icons.glyphs.folder[node.open and "arrow_open" or "arrow_closed"]
11-
return string.rep(" ", depth - 2) .. icon .. " "
12-
end
13-
return string.rep(" ", depth)
14-
end
15-
end
16-
17-
local function get_padding_indent_markers(depth, idx, nodes_number, _, markers)
3+
local function get_padding_indent_markers(depth, idx, nodes_number, markers)
184
local padding = ""
5+
196
if depth ~= 0 then
207
local rdepth = depth / 2
218
markers[rdepth] = idx ~= nodes_number
@@ -34,14 +21,30 @@ local function get_padding_indent_markers(depth, idx, nodes_number, _, markers)
3421
return padding
3522
end
3623

37-
function M.reload_padding_function()
38-
if M.config.icons.show.folder and M.config.icons.show.folder_arrow then
39-
M.get_padding = get_padding_arrows()
24+
local function get_padding_arrows(node, indent)
25+
if node.nodes then
26+
return M.config.icons.glyphs.folder[node.open and "arrow_open" or "arrow_closed"] .. " "
27+
elseif indent then
28+
return " "
29+
else
30+
return ""
4031
end
32+
end
33+
34+
function M.get_padding(depth, idx, nodes_number, node, markers)
35+
local padding = ""
4136

4237
if M.config.indent_markers.enable then
43-
M.get_padding = get_padding_indent_markers
38+
padding = padding .. get_padding_indent_markers(depth, idx, nodes_number, markers)
39+
else
40+
padding = padding .. string.rep(" ", depth)
4441
end
42+
43+
if M.config.icons.show.folder_arrow then
44+
padding = padding .. get_padding_arrows(node, not M.config.indent_markers.enable)
45+
end
46+
47+
return padding
4548
end
4649

4750
function M.setup(opts)

lua/nvim-tree/renderer/init.lua

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ function M.render_hl(bufnr, hl)
4040
end
4141
end
4242

43-
local function should_show_arrows()
44-
return not M.config.indent_markers.enable and M.config.icons.show.folder and M.config.icons.show.folder_arrow
45-
end
46-
4743
local picture_map = {
4844
jpg = true,
4945
jpeg = true,
@@ -60,7 +56,6 @@ function M.draw()
6056
local ps = log.profile_start "draw"
6157

6258
local cursor = api.nvim_win_get_cursor(view.get_winnr())
63-
_padding.reload_padding_function()
6459
icon_component.reset_config()
6560

6661
local lines, hl
@@ -69,7 +64,6 @@ function M.draw()
6964
lines, hl = help.compute_lines()
7065
else
7166
lines, hl, signs = Builder.new(core.get_cwd())
72-
:configure_initial_depth(should_show_arrows())
7367
:configure_root_modifier(M.config.root_folder_modifier)
7468
:configure_trailing_slash(M.config.add_trailing)
7569
:configure_special_files(M.config.special_files)

lua/nvim-tree/view.lua

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ local M = {}
44

55
local events = require "nvim-tree.events"
66

7+
local function get_win_sep_hl()
8+
-- #1221 WinSeparator not present in nvim 0.6.1 and some builds of 0.7.0
9+
local has_win_sep = pcall(vim.cmd, "silent hi WinSeparator")
10+
return has_win_sep and "WinSeparator:NvimTreeWinSeparator" or "VertSplit:NvimTreeWinSeparator"
11+
end
12+
713
M.View = {
814
adaptive_size = false,
915
centralize_selection = false,
@@ -29,9 +35,7 @@ M.View = {
2935
"EndOfBuffer:NvimTreeEndOfBuffer",
3036
"Normal:NvimTreeNormal",
3137
"CursorLine:NvimTreeCursorLine",
32-
-- #1221 WinSeparator not present in nvim 0.6.1 and some builds of 0.7.0
33-
pcall(vim.cmd, "silent hi WinSeparator") and "WinSeparator:NvimTreeWinSeparator"
34-
or "VertSplit:NvimTreeWinSeparator",
38+
get_win_sep_hl(),
3539
"StatusLine:NvimTreeStatusLine",
3640
"StatusLineNC:NvimTreeStatuslineNC",
3741
"SignColumn:NvimTreeSignColumn",

0 commit comments

Comments
 (0)