@@ -206,7 +206,7 @@ function Builder:_highlight_opened_files(node, offset, icon_length, git_icons_le
206206 self :_insert_highlight (" NvimTreeOpenedFile" , from , to )
207207end
208208
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 )
210210 local offset = string.len (padding )
211211
212212 local icon = self :_build_file_icon (node , offset )
@@ -228,7 +228,9 @@ function Builder:_build_file(node, padding, git_highlight, git_icons_tbl)
228228 self :_insert_highlight (" NvimTreeImageFile" , col_start , col_end )
229229 end
230230
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
232234 if should_highlight_opened_files then
233235 self :_highlight_opened_files (node , offset , # icon , git_icons_length )
234236 end
@@ -238,7 +240,7 @@ function Builder:_build_file(node, padding, git_highlight, git_icons_tbl)
238240 end
239241end
240242
241- function Builder :_build_line (node , idx , num_children )
243+ function Builder :_build_line (node , idx , num_children , unloaded_bufnr )
242244 local padding = pad .get_padding (self .depth , idx , num_children , node , self .markers )
243245
244246 if string.len (padding ) > 0 then
@@ -262,13 +264,13 @@ function Builder:_build_line(node, idx, num_children)
262264 elseif is_symlink then
263265 self :_build_symlink (node , padding , git_highlight , git_icons_tbl )
264266 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 )
266268 end
267269 self .index = self .index + 1
268270
269271 if node .open then
270272 self .depth = self .depth + 1
271- self :build (node )
273+ self :build (node , unloaded_bufnr )
272274 self .depth = self .depth - 1
273275 end
274276end
@@ -287,12 +289,12 @@ function Builder:_get_nodes_number(nodes)
287289 return i
288290end
289291
290- function Builder :build (tree )
292+ function Builder :build (tree , unloaded_bufnr )
291293 local num_children = self :_get_nodes_number (tree .nodes )
292294 local idx = 1
293295 for _ , node in ipairs (tree .nodes ) do
294296 if not node .hidden then
295- self :_build_line (node , idx , num_children )
297+ self :_build_line (node , idx , num_children , unloaded_bufnr )
296298 idx = idx + 1
297299 end
298300 end
0 commit comments