@@ -4,10 +4,6 @@ local git = require "nvim-tree.renderer.components.git"
4
4
local pad = require " nvim-tree.renderer.components.padding"
5
5
local icons = require " nvim-tree.renderer.components.icons"
6
6
7
- -- TODO(refactor): the builder abstraction is not perfect yet. We shouldn't leak data in components.
8
- -- Components should return only and icon / highlight group pair at most.
9
- -- Only missing git refactoring
10
-
11
7
local Builder = {}
12
8
Builder .__index = Builder
13
9
@@ -59,6 +55,11 @@ function Builder:configure_opened_file_highlighting(level)
59
55
return self
60
56
end
61
57
58
+ function Builder :configure_git_icons_padding (padding )
59
+ self .git_icon_padding = padding or " "
60
+ return self
61
+ end
62
+
62
63
function Builder :_insert_highlight (group , start , end_ )
63
64
table.insert (self .highlights , { group , self .index , start , end_ or - 1 })
64
65
end
@@ -77,13 +78,29 @@ local function get_folder_name(node)
77
78
return name
78
79
end
79
80
81
+ function Builder :_unwrap_git_data (git_icons_and_hl_groups , offset )
82
+ if not git_icons_and_hl_groups then
83
+ return " "
84
+ end
85
+
86
+ local icon = " "
87
+ for _ , v in ipairs (git_icons_and_hl_groups ) do
88
+ if # v .icon > 0 then
89
+ self :_insert_highlight (v .hl , offset + # icon , offset + # icon + # v .icon )
90
+ icon = icon .. v .icon .. self .git_icon_padding
91
+ end
92
+ end
93
+ return icon
94
+ end
95
+
80
96
function Builder :_build_folder (node , padding , git_hl )
81
97
local offset = string.len (padding )
82
98
83
99
local name = get_folder_name (node )
84
100
local has_children = # node .nodes ~= 0 or node .has_children
85
101
local icon = icons .get_folder_icon (node .open , node .link_to ~= nil , has_children )
86
- local git_icon = git .get_icons (node , self .index , offset , # icon , self .highlights ) or " "
102
+ local git_icon = self :_unwrap_git_data (git .get_icons (node ), offset + # icon )
103
+
87
104
local line = padding .. icon .. git_icon .. name .. self .trailing_slash
88
105
89
106
self :_insert_line (line )
@@ -122,15 +139,15 @@ end
122
139
123
140
function Builder :_build_file_icons (node , offset )
124
141
if self .special_map [node .absolute_path ] or self .special_map [node .name ] then
125
- local git_icons = git .get_icons (node , self . index , offset , 0 , self . highlights )
142
+ local git_icons = self : _unwrap_git_data ( git .get_icons (node ), offset + # icons . i . special )
126
143
self :_insert_highlight (" NvimTreeSpecialFile" , offset + # git_icons )
127
144
return icons .i .special , git_icons
128
145
else
129
146
local icon , hl_group = icons .get_file_icon (node .name , node .extension )
130
147
if hl_group then
131
148
self :_insert_highlight (hl_group , offset , offset + # icon )
132
149
end
133
- return icon , git .get_icons (node , self . index , offset , # icon , self . highlights )
150
+ return icon , self : _unwrap_git_data ( git .get_icons (node ), offset + # icon )
134
151
end
135
152
end
136
153
0 commit comments