@@ -358,23 +358,31 @@ function Builder:build_line(node, idx, num_children)
358358 self .depth = self .depth + 1
359359 self :build_lines (node )
360360 self .depth = self .depth - 1
361- self :add_hidden_count_string (node , idx , num_children )
362361 end
363362end
364363
364+ --- Add virtual lines for rendering hidden count information per node
365365--- @private
366366function Builder :add_hidden_count_string (node , idx , num_children )
367+ if not node .open then
368+ return
369+ end
367370 local hidden_count_string = M .opts .renderer .hidden_display (node .hidden_count )
368371 if hidden_count_string and hidden_count_string ~= " " then
369- local indent_markers = pad .get_indent_markers (math.max ( self .depth , 0 ), idx or 0 , num_children or 0 , node , self .markers )
372+ local indent_markers = pad .get_indent_markers (self .depth , idx or 0 , num_children or 0 , node , self .markers , 1 )
370373 local indent_width = M .opts .renderer .indent_width
371- local indent_string = string.rep (" " , indent_width ) .. (indent_markers .str or " " )
372- table.insert (self .virtual_lines , {
373- indent_string = indent_string ,
374- depth = self .depth ,
375- line_nr = # self .lines - 1 ,
376- -- Remove padding if we're in root
377- text = (node .parent == nil and " " or string.rep (" " , indent_width )) .. hidden_count_string ,
374+
375+ local indent_padding = string.rep (" " , indent_width )
376+ local indent_string = indent_padding .. indent_markers .str
377+ local line_nr = # self .lines - 1
378+ self .virtual_lines [line_nr ] = self .virtual_lines [line_nr ] or {}
379+
380+ -- NOTE: We are inserting in depth order because of current traversal
381+ -- if we change the traversal, we might need to sort by depth before rendering `self.virtual_lines`
382+ -- to maintain proper ordering of parent and child folder hidden count info.
383+ table.insert (self .virtual_lines [line_nr ], {
384+ { indent_string , indent_markers .hl },
385+ { string.rep (indent_padding , (node .parent == nil and 0 or 1 )) .. hidden_count_string , " NvimTreeHiddenDisplay" },
378386 })
379387 end
380388end
@@ -408,6 +416,7 @@ function Builder:build_lines(node)
408416 idx = idx + 1
409417 end
410418 end
419+ self :add_hidden_count_string (node )
411420end
412421
413422--- @private
@@ -458,24 +467,10 @@ end
458467function Builder :build ()
459468 self :build_header ()
460469 self :build_lines ()
461- self :build_root_hidden_count ()
462470 self :sanitize_lines ()
463471 return self
464472end
465473
466- --- Add the hidden_count for root, since root dir is treated differently
467- --- from normal directories we need to do it again for root.
468- --- Also need to sort by depth
469- --- @private
470- function Builder :build_root_hidden_count ()
471- local root = core .get_explorer ()
472- self :add_hidden_count_string (root )
473- -- Now that we're done, we must sort by depth, to ensure proper rendering
474- table.sort (self .virtual_lines , function (a , b )
475- return a .depth < b .depth
476- end )
477- end
478-
479474--- @param opts table
480475local setup_hidden_display_function = function (opts )
481476 local hidden_display = opts .renderer .hidden_display
0 commit comments