@@ -206,7 +206,7 @@ function Builder:_highlight_opened_files(node, offset, icon_length, git_icons_le
206
206
self :_insert_highlight (" NvimTreeOpenedFile" , from , to )
207
207
end
208
208
209
- function Builder :_build_file (node , padding , git_highlight , git_icons_tbl )
209
+ function Builder :_build_file (node , padding , git_highlight , git_icons_tbl , unloaded_bufnr )
210
210
local offset = string.len (padding )
211
211
212
212
local icon = self :_build_file_icon (node , offset )
@@ -228,7 +228,9 @@ function Builder:_build_file(node, padding, git_highlight, git_icons_tbl)
228
228
self :_insert_highlight (" NvimTreeImageFile" , col_start , col_end )
229
229
end
230
230
231
- local should_highlight_opened_files = self .highlight_opened_files and vim .fn .bufloaded (node .absolute_path ) > 0
231
+ local should_highlight_opened_files = self .highlight_opened_files
232
+ and vim .fn .bufloaded (node .absolute_path ) > 0
233
+ and vim .fn .bufnr (node .absolute_path ) ~= unloaded_bufnr
232
234
if should_highlight_opened_files then
233
235
self :_highlight_opened_files (node , offset , # icon , git_icons_length )
234
236
end
@@ -238,7 +240,7 @@ function Builder:_build_file(node, padding, git_highlight, git_icons_tbl)
238
240
end
239
241
end
240
242
241
- function Builder :_build_line (node , idx , num_children )
243
+ function Builder :_build_line (node , idx , num_children , unloaded_bufnr )
242
244
local padding = pad .get_padding (self .depth , idx , num_children , node , self .markers )
243
245
244
246
if string.len (padding ) > 0 then
@@ -262,13 +264,13 @@ function Builder:_build_line(node, idx, num_children)
262
264
elseif is_symlink then
263
265
self :_build_symlink (node , padding , git_highlight , git_icons_tbl )
264
266
else
265
- self :_build_file (node , padding , git_highlight , git_icons_tbl )
267
+ self :_build_file (node , padding , git_highlight , git_icons_tbl , unloaded_bufnr )
266
268
end
267
269
self .index = self .index + 1
268
270
269
271
if node .open then
270
272
self .depth = self .depth + 1
271
- self :build (node )
273
+ self :build (node , unloaded_bufnr )
272
274
self .depth = self .depth - 1
273
275
end
274
276
end
@@ -287,12 +289,12 @@ function Builder:_get_nodes_number(nodes)
287
289
return i
288
290
end
289
291
290
- function Builder :build (tree )
292
+ function Builder :build (tree , unloaded_bufnr )
291
293
local num_children = self :_get_nodes_number (tree .nodes )
292
294
local idx = 1
293
295
for _ , node in ipairs (tree .nodes ) do
294
296
if not node .hidden then
295
- self :_build_line (node , idx , num_children )
297
+ self :_build_line (node , idx , num_children , unloaded_bufnr )
296
298
idx = idx + 1
297
299
end
298
300
end
0 commit comments