Skip to content

Commit 9a02ded

Browse files
committed
fix(renderer): indent markers with arrows
breaking: glyphs for indent markers should only be one block large
1 parent 19425c5 commit 9a02ded

File tree

3 files changed

+38
-15
lines changed

3 files changed

+38
-15
lines changed

doc/nvim-tree-lua.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ Subsequent calls to setup will replace the previous configuration.
201201
indent_markers = {
202202
enable = false,
203203
icons = {
204-
corner = "└ ",
205-
edge = "│ ",
206-
item = "│ ",
207-
none = " ",
204+
corner = "└",
205+
edge = "│",
206+
item = "│",
207+
none = " ",
208208
},
209209
},
210210
icons = {
@@ -644,7 +644,7 @@ UI rendering setup
644644

645645
*nvim-tree.renderer.indent_markers.icons*
646646
Icons shown before the file/directory.
647-
Type: `table`, Default: `{ corner = "└ ", edge = "│ ", item = "│ ", none = " ", }`
647+
Type: `table`, Default: `{ corner = "└", edge = "│", item = "│", none = " ", }`
648648

649649
*nvim-tree.renderer.icons*
650650
Configuration options for icons.

lua/nvim-tree.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,10 +449,10 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
449449
indent_markers = {
450450
enable = false,
451451
icons = {
452-
corner = " ",
453-
edge = " ",
454-
item = " ",
455-
none = " ",
452+
corner = "",
453+
edge = "",
454+
item = "",
455+
none = " ",
456456
},
457457
},
458458
icons = {

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

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

3+
local function check_siblings_for_folder(node, with_arrows)
4+
if with_arrows then
5+
for _, n in pairs(node.parent.nodes) do
6+
if n.nodes then
7+
return true
8+
end
9+
end
10+
end
11+
return false
12+
end
13+
314
local function get_padding_indent_markers(depth, idx, nodes_number, markers, with_arrows, node)
4-
local default_padding = with_arrows and (not node.nodes or depth > 0) and " " or ""
5-
local padding = depth == 0 and default_padding or ""
15+
local base_padding = with_arrows and (not node.nodes or depth > 0) and " " or ""
16+
local padding = base_padding
617

718
if depth > 0 then
19+
local has_folder_sibling = check_siblings_for_folder(node, with_arrows)
820
local rdepth = depth / 2
921
markers[rdepth] = idx ~= nodes_number
1022
for i = 1, rdepth do
23+
local glyph
1124
if idx == nodes_number and i == rdepth then
12-
padding = padding .. default_padding .. M.config.indent_markers.icons.corner
25+
glyph = M.config.indent_markers.icons.corner
1326
elseif markers[i] and i == rdepth then
14-
padding = padding .. default_padding .. M.config.indent_markers.icons.item
27+
glyph = M.config.indent_markers.icons.item
1528
elseif markers[i] then
16-
padding = padding .. default_padding .. M.config.indent_markers.icons.edge
29+
glyph = M.config.indent_markers.icons.edge
30+
else
31+
glyph = M.config.indent_markers.icons.none
32+
end
33+
34+
if not with_arrows or i == 1 then
35+
padding = padding .. glyph .. " "
36+
elseif idx == nodes_number and i == rdepth and has_folder_sibling then
37+
padding = padding .. base_padding .. glyph .. "── "
38+
elseif rdepth == i and not node.nodes and has_folder_sibling then
39+
padding = padding .. base_padding .. glyph .. " " .. base_padding
1740
else
18-
padding = padding .. default_padding .. M.config.indent_markers.icons.none
41+
padding = padding .. base_padding .. glyph .. " "
1942
end
2043
end
2144
end

0 commit comments

Comments
 (0)