Skip to content

Commit 42fbf37

Browse files
committed
feat: add config option for a tree indent width
add 'indent_width' option to configure visible indent for tree nesting levels (default is 2).
1 parent 261a5c3 commit 42fbf37

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed

doc/nvim-tree-lua.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ Subsequent calls to setup will replace the previous configuration.
213213
full_name = false,
214214
highlight_opened_files = "none",
215215
root_folder_modifier = ":~",
216+
indent_width = 2,
216217
indent_markers = {
217218
enable = false,
218219
inline_arrows = true,
@@ -709,6 +710,10 @@ UI rendering setup
709710
available options.
710711
Type: `string`, Default: `":~"`
711712

713+
*nvim-tree.renderer.indent_width*
714+
Number of spaces for an each tree nesting level.
715+
Type: `number`, Default: `2`
716+
712717
*nvim-tree.renderer.indent_markers*
713718
Configuration options for tree indent markers.
714719

lua/nvim-tree.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
476476
full_name = false,
477477
highlight_opened_files = "none",
478478
root_folder_modifier = ":~",
479+
indent_width = 2,
479480
indent_markers = {
480481
enable = false,
481482
inline_arrows = true,

lua/nvim-tree/renderer/builder.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ function Builder:_build_line(node, idx, num_children)
258258
self.index = self.index + 1
259259

260260
if node.open then
261-
self.depth = self.depth + 2
261+
self.depth = self.depth + 1
262262
self:build(node)
263-
self.depth = self.depth - 2
263+
self.depth = self.depth - 1
264264
end
265265
end
266266

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,30 @@ local function get_padding_indent_markers(depth, idx, nodes_number, markers, wit
2525

2626
if depth > 0 then
2727
local has_folder_sibling = check_siblings_for_folder(node, with_arrows)
28-
local rdepth = depth / 2
29-
markers[rdepth] = idx ~= nodes_number
30-
for i = 1, rdepth do
28+
local indent = string.rep(" ", M.config.indent_width - 1)
29+
markers[depth] = idx ~= nodes_number
30+
for i = 1, depth do
3131
local glyph
32-
if idx == nodes_number and i == rdepth then
32+
if idx == nodes_number and i == depth then
3333
glyph = M.config.indent_markers.icons.corner
34-
elseif markers[i] and i == rdepth then
34+
elseif markers[i] and i == depth then
3535
glyph = M.config.indent_markers.icons.item
3636
elseif markers[i] then
3737
glyph = M.config.indent_markers.icons.edge
3838
else
3939
glyph = M.config.indent_markers.icons.none
4040
end
4141

42-
if not with_arrows or (inline_arrows and (rdepth ~= i or not node.nodes)) then
43-
padding = padding .. glyph .. " "
42+
if not with_arrows or (inline_arrows and (depth ~= i or not node.nodes)) then
43+
padding = padding .. glyph .. indent
4444
elseif inline_arrows then
4545
padding = padding
46-
elseif idx == nodes_number and i == rdepth and has_folder_sibling then
47-
padding = padding .. base_padding .. glyph .. "── "
48-
elseif rdepth == i and not node.nodes and has_folder_sibling then
49-
padding = padding .. base_padding .. glyph .. " " .. base_padding
46+
elseif idx == nodes_number and i == depth and has_folder_sibling then
47+
padding = padding .. base_padding .. glyph .. "──" .. indent
48+
elseif depth == i and not node.nodes and has_folder_sibling then
49+
padding = padding .. base_padding .. glyph .. indent .. base_padding
5050
else
51-
padding = padding .. base_padding .. glyph .. " "
51+
padding = padding .. base_padding .. glyph .. indent
5252
end
5353
end
5454
end
@@ -71,11 +71,12 @@ function M.get_padding(depth, idx, nodes_number, node, markers)
7171
local show_arrows = M.config.icons.show.folder_arrow
7272
local show_markers = M.config.indent_markers.enable
7373
local inline_arrows = M.config.indent_markers.inline_arrows
74+
local indent_width = M.config.indent_width
7475

7576
if show_markers then
7677
padding = padding .. get_padding_indent_markers(depth, idx, nodes_number, markers, show_arrows, inline_arrows, node)
7778
else
78-
padding = padding .. string.rep(" ", depth)
79+
padding = padding .. string.rep(" ", depth * indent_width)
7980
end
8081

8182
if show_arrows then

0 commit comments

Comments
 (0)