@@ -116,26 +116,39 @@ function Builder:_unwrap_git_data(git_icons_and_hl_groups, offset)
116
116
return icon
117
117
end
118
118
119
+ --- return modified icon if node is modified, otherwise return empty string
120
+ --- @param node table
121
+ --- @return string modified icon
122
+ function Builder :_get_modified_icon (node )
123
+ if not modified .is_modified (node ) or self .modified .placement == " signcolumn" then
124
+ return " "
125
+ end
126
+
127
+ return self .modified .placement == " before" and self .modified .icon .. " " or " " .. self .modified .icon
128
+ end
129
+
119
130
function Builder :_build_folder (node , padding , git_hl , git_icons_tbl )
120
131
local offset = string.len (padding )
121
132
122
- local name = get_folder_name (node )
123
- if modified .is_modified (node ) then
124
- name = name .. self .modified .icon
125
- end
126
133
local has_children = # node .nodes ~= 0 or node .has_children
127
134
local icon = icons .get_folder_icon (node .open , node .link_to ~= nil , has_children )
128
135
129
- local foldername = name .. self .trailing_slash
136
+ local foldername = get_folder_name ( node ) .. self .trailing_slash
130
137
if node .link_to and self .symlink_destination then
131
138
local arrow = icons .i .symlink_arrow
132
139
local link_to = utils .path_relative (node .link_to , core .get_cwd ())
133
140
foldername = foldername .. arrow .. link_to
134
141
end
135
142
136
143
local git_icons = self :_unwrap_git_data (git_icons_tbl , offset + # icon + (self .is_git_after and # foldername + 1 or 0 ))
137
- local fname_starts_at = offset + # icon + (self .is_git_after and 0 or # git_icons )
138
- local line = self :_format_line (padding .. icon , foldername , git_icons )
144
+ local modified_icon = self :_get_modified_icon (node )
145
+
146
+ -- TODO: this is duplicated logic with _build_file & _build_symlink
147
+ local fname_starts_at = offset
148
+ + # icon
149
+ + (self .is_git_after and 0 or # git_icons )
150
+ + (self .modified .placement ~= " before" and 0 or # modified_icon )
151
+ local line = self :_format_line (padding .. icon , foldername , git_icons , modified_icon )
139
152
self :_insert_line (line )
140
153
141
154
if # icon > 0 then
@@ -162,13 +175,24 @@ function Builder:_build_folder(node, padding, git_hl, git_icons_tbl)
162
175
end
163
176
end
164
177
165
- function Builder :_format_line (before , after , git_icons )
178
+ --- format line
179
+ --- @param before string
180
+ --- @param after string
181
+ --- @param git_icons string | nil
182
+ --- @param modified_icon string
183
+ --- @return string
184
+ function Builder :_format_line (before , after , git_icons , modified_icon )
166
185
git_icons = self .is_git_after and git_icons and " " .. git_icons or git_icons
186
+
187
+ local is_modified_after = self .modified .placement ~= " before"
188
+
167
189
return string.format (
168
- " %s%s%s%s" ,
190
+ " %s%s%s%s%s%s " ,
169
191
before ,
170
192
self .is_git_after and " " or git_icons ,
193
+ is_modified_after and " " or modified_icon ,
171
194
after ,
195
+ is_modified_after and modified_icon or " " ,
172
196
self .is_git_after and git_icons or " "
173
197
)
174
198
end
@@ -188,9 +212,14 @@ function Builder:_build_symlink(node, padding, git_highlight, git_icons_tbl)
188
212
189
213
local git_icons_starts_at = offset + # icon + (self .is_git_after and # symlink_formatted + 1 or 0 )
190
214
local git_icons = self :_unwrap_git_data (git_icons_tbl , git_icons_starts_at )
191
- local line = self :_format_line (padding .. icon , symlink_formatted , git_icons )
215
+ local modified_icon = self :_get_modified_icon (node )
216
+ local line = self :_format_line (padding .. icon , symlink_formatted , git_icons , modified_icon )
192
217
193
- self :_insert_highlight (link_highlight , offset + (self .is_git_after and 0 or # git_icons ), string.len (line ))
218
+ self :_insert_highlight (
219
+ link_highlight ,
220
+ offset + (self .is_git_after and 0 or # git_icons ) + (self .modified .placement ~= " before" and 0 or # modified_icon ),
221
+ string.len (line )
222
+ )
194
223
self :_insert_line (line )
195
224
end
196
225
@@ -226,14 +255,12 @@ function Builder:_build_file(node, padding, git_highlight, git_icons_tbl, unload
226
255
local git_icons_starts_at = offset + # icon + (self .is_git_after and # node .name + 1 or 0 )
227
256
local git_icons = self :_unwrap_git_data (git_icons_tbl , git_icons_starts_at )
228
257
229
- local name = node .name
230
- if modified .is_modified (node ) then
231
- name = name .. self .modified .icon
232
- end
233
- self :_insert_line (self :_format_line (padding .. icon , name , git_icons ))
258
+ local modified_icon = self :_get_modified_icon (node )
259
+ self :_insert_line (self :_format_line (padding .. icon , node .name , git_icons , modified_icon ))
234
260
235
261
local git_icons_length = self .is_git_after and 0 or # git_icons
236
- local col_start = offset + # icon + git_icons_length
262
+ local modified_icon_length = self .modified .placement ~= " before" and 0 or # modified_icon
263
+ local col_start = offset + # icon + git_icons_length + modified_icon_length
237
264
local col_end = col_start + # node .name
238
265
239
266
if vim .tbl_contains (self .special_files , node .absolute_path ) or vim .tbl_contains (self .special_files , node .name ) then
0 commit comments