Skip to content

Commit 4f499d9

Browse files
committed
finish indent markers properly
1 parent 7988dd4 commit 4f499d9

File tree

5 files changed

+30
-25
lines changed

5 files changed

+30
-25
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ let g:lua_tree_ignore = [ '.git', 'node_modules', '.cache' ] "empty by default
3030
let g:lua_tree_auto_open = 1 "0 by default, opens the tree when typing `vim $DIR` or `vim`
3131
let g:lua_tree_auto_close = 1 "0 by default, closes the tree when it's the last window
3232
let g:lua_tree_follow = 1 "0 by default, this option allows the cursor to be updated when entering a buffer
33+
let g:lua_tree_indent_markers = 1 "0 by default, this option shows indent markers when folders are open
3334
let g:lua_tree_show_icons = {
3435
\ 'git': 1,
3536
\ 'folders': 0,
@@ -113,6 +114,7 @@ This plugin is very fast because it uses the `libuv` `scandir` and `scandir_next
113114
- Change directory with `.`
114115
- Add / Rename / delete files
115116
- Git integration
117+
- Indent markers
116118
- Mouse support
117119
- It's fast
118120

doc/nvim-tree-lua.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ Can be `0` or `1`. When `1`, will disable all keybindings by the plugin.
121121
|g:lua_tree_bindings| as well as default bindings will not take effect.
122122
Default is 0
123123

124+
|g:lua_tree_indent_markers| *g:lua_tree_indent_markers*
125+
126+
Can be `0` or `1`. When `1`, will display indent markers when folders are open
124127

125128
==============================================================================
126129
INFORMATIONS *nvim-tree-info*
@@ -209,6 +212,7 @@ LuaTreeExecFile
209212
LuaTreeSpecialFile
210213
LuaTreeImageFile
211214
LuaTreeMarkdownFile
215+
LuaTreeIndentMarker
212216

213217
LuaTreeLicenseIcon
214218
LuaTreeYamlIcon

doc/tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ g:lua_tree_bindings nvim-tree-lua.txt /*g:lua_tree_bindings*
99
g:lua_tree_follow nvim-tree-lua.txt /*g:lua_tree_follow*
1010
g:lua_tree_icons nvim-tree-lua.txt /*g:lua_tree_icons*
1111
g:lua_tree_ignore nvim-tree-lua.txt /*g:lua_tree_ignore*
12+
g:lua_tree_indent_markers nvim-tree-lua.txt /*g:lua_tree_indent_markers*
1213
g:lua_tree_show_icons nvim-tree-lua.txt /*g:lua_tree_show_icons*
1314
g:lua_tree_side nvim-tree-lua.txt /*g:lua_tree_side*
1415
g:lua_tree_size nvim-tree-lua.txt /*g:lua_tree_size*

lua/lib/colors.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ local function get_hl_groups()
2929
local colors = get_colors()
3030

3131
return {
32+
IndentMarker = { fg = '#90a4ae' },
3233
Symlink = { gui = 'bold', fg = colors.cyan },
3334
FolderIcon = { fg = '#90a4ae' },
3435

lua/lib/renderer.lua

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -88,28 +88,22 @@ if icon_state.show_git_icon then
8888
end
8989

9090
local get_padding = function(depth)
91-
return string.rep(' ', depth), 0
91+
return string.rep(' ', depth)
9292
end
9393

94-
local add_padding_glyph = true
9594
if vim.g.lua_tree_indent_markers == 1 then
9695
get_padding = function(depth, idx, tree, node)
9796
local padding = ""
98-
local offset = 0
9997
if depth ~= 0 then
100-
padding = string.rep(" ", depth-2)
101-
if add_padding_glyph and (idx == #tree.entries or node.open) then
102-
padding = padding..''
103-
offset = string.len('') -2
104-
add_padding_glyph = false
105-
elseif add_padding_glyph then
106-
padding = padding..''
107-
offset = string.len('') -2
108-
else
109-
padding = padding..' '
98+
for i=1,depth/2 do
99+
if idx == #tree.entries and i == depth/2 then
100+
padding = padding..''
101+
else
102+
padding = padding..''
103+
end
110104
end
111105
end
112-
return padding, offset
106+
return padding
113107
end
114108
end
115109

@@ -134,13 +128,16 @@ local function update_draw_data(tree, depth)
134128
index = 1
135129
end
136130

137-
add_padding_glyph = true
138131
for idx, node in ipairs(tree.entries) do
139-
local padding, offset = get_padding(depth, idx, tree, node, add_padding_glyph)
132+
local padding = get_padding(depth, idx, tree, node)
133+
local offset = string.len(padding)
134+
if depth > 0 then
135+
table.insert(hl, { 'LuaTreeIndentMarker', index, 0, offset })
136+
end
140137
if node.entries then
141138
local icon = get_folder_icon(node.open)
142-
local git_icon = get_git_icons(node, index, depth+offset+#node.name, #icon+1)
143-
set_folder_hl(index, depth+offset, #icon, #node.name)
139+
local git_icon = get_git_icons(node, index, offset+#node.name, #icon+1)
140+
set_folder_hl(index, offset, #icon, #node.name)
144141
index = index + 1
145142
if node.open then
146143
table.insert(lines, padding..icon..node.name.." "..git_icon)
@@ -149,7 +146,7 @@ local function update_draw_data(tree, depth)
149146
table.insert(lines, padding..icon..node.name.." "..git_icon)
150147
end
151148
elseif node.link_to then
152-
table.insert(hl, { 'LuaTreeSymlink', index, depth+offset, -1 })
149+
table.insert(hl, { 'LuaTreeSymlink', index, offset, -1 })
153150
table.insert(lines, padding..node.name..""..node.link_to)
154151
index = index + 1
155152

@@ -158,17 +155,17 @@ local function update_draw_data(tree, depth)
158155
local git_icons
159156
if special[node.name] then
160157
icon = ""
161-
git_icons = get_git_icons(node, index, depth+offset, 0)
162-
table.insert(hl, {'LuaTreeSpecialFile', index, depth+offset+#git_icons, -1})
158+
git_icons = get_git_icons(node, index, offset, 0)
159+
table.insert(hl, {'LuaTreeSpecialFile', index, offset+#git_icons, -1})
163160
else
164-
icon = get_file_icon(node.name, node.extension, index, depth+offset)
165-
git_icons = get_git_icons(node, index, depth+offset, #icon)
161+
icon = get_file_icon(node.name, node.extension, index, offset)
162+
git_icons = get_git_icons(node, index, offset, #icon)
166163
end
167164
table.insert(lines, padding..icon..git_icons..node.name)
168165
if node.executable then
169-
table.insert(hl, {'LuaTreeExecFile', index, depth+offset+#icon+#git_icons, -1 })
166+
table.insert(hl, {'LuaTreeExecFile', index, offset+#icon+#git_icons, -1 })
170167
elseif picture[node.extension] then
171-
table.insert(hl, {'LuaTreeImageFile', index, depth+offset+#icon+#git_icons, -1 })
168+
table.insert(hl, {'LuaTreeImageFile', index, offset+#icon+#git_icons, -1 })
172169
end
173170
index = index + 1
174171
end

0 commit comments

Comments
 (0)