Skip to content

Commit 3bcfc70

Browse files
authored
Merge pull request #43 from kyazdani42/feat/indent-markers
add indent markers
2 parents fff623e + 4f499d9 commit 3bcfc70

File tree

5 files changed

+43
-11
lines changed

5 files changed

+43
-11
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: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,26 @@ if icon_state.show_git_icon then
8787
end
8888
end
8989

90+
local get_padding = function(depth)
91+
return string.rep(' ', depth)
92+
end
93+
94+
if vim.g.lua_tree_indent_markers == 1 then
95+
get_padding = function(depth, idx, tree, node)
96+
local padding = ""
97+
if depth ~= 0 then
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
104+
end
105+
end
106+
return padding
107+
end
108+
end
109+
90110
local picture = {
91111
jpg = true,
92112
jpeg = true,
@@ -108,12 +128,16 @@ local function update_draw_data(tree, depth)
108128
index = 1
109129
end
110130

111-
for _, node in ipairs(tree.entries) do
112-
local padding = string.rep(" ", depth)
131+
for idx, node in ipairs(tree.entries) do
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
113137
if node.entries then
114138
local icon = get_folder_icon(node.open)
115-
local git_icon = get_git_icons(node, index, depth+#node.name, #icon+1)
116-
set_folder_hl(index, depth, #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)
117141
index = index + 1
118142
if node.open then
119143
table.insert(lines, padding..icon..node.name.." "..git_icon)
@@ -122,7 +146,7 @@ local function update_draw_data(tree, depth)
122146
table.insert(lines, padding..icon..node.name.." "..git_icon)
123147
end
124148
elseif node.link_to then
125-
table.insert(hl, { 'LuaTreeSymlink', index, depth, -1 })
149+
table.insert(hl, { 'LuaTreeSymlink', index, offset, -1 })
126150
table.insert(lines, padding..node.name..""..node.link_to)
127151
index = index + 1
128152

@@ -131,17 +155,17 @@ local function update_draw_data(tree, depth)
131155
local git_icons
132156
if special[node.name] then
133157
icon = ""
134-
git_icons = get_git_icons(node, index, depth, 0)
135-
table.insert(hl, {'LuaTreeSpecialFile', index, depth+#git_icons, -1})
158+
git_icons = get_git_icons(node, index, offset, 0)
159+
table.insert(hl, {'LuaTreeSpecialFile', index, offset+#git_icons, -1})
136160
else
137-
icon = get_file_icon(node.name, node.extension, index, depth)
138-
git_icons = get_git_icons(node, index, depth, #icon)
161+
icon = get_file_icon(node.name, node.extension, index, offset)
162+
git_icons = get_git_icons(node, index, offset, #icon)
139163
end
140164
table.insert(lines, padding..icon..git_icons..node.name)
141165
if node.executable then
142-
table.insert(hl, {'LuaTreeExecFile', index, depth+#icon+#git_icons, -1 })
166+
table.insert(hl, {'LuaTreeExecFile', index, offset+#icon+#git_icons, -1 })
143167
elseif picture[node.extension] then
144-
table.insert(hl, {'LuaTreeImageFile', index, depth+#icon+#git_icons, -1 })
168+
table.insert(hl, {'LuaTreeImageFile', index, offset+#icon+#git_icons, -1 })
145169
end
146170
index = index + 1
147171
end

0 commit comments

Comments
 (0)