@@ -358,23 +358,31 @@ function Builder:build_line(node, idx, num_children)
358
358
self .depth = self .depth + 1
359
359
self :build_lines (node )
360
360
self .depth = self .depth - 1
361
- self :add_hidden_count_string (node , idx , num_children )
362
361
end
363
362
end
364
363
364
+ --- Add virtual lines for rendering hidden count information per node
365
365
--- @private
366
366
function Builder :add_hidden_count_string (node , idx , num_children )
367
+ if not node .open then
368
+ return
369
+ end
367
370
local hidden_count_string = M .opts .renderer .hidden_display (node .hidden_count )
368
371
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 )
370
373
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" },
378
386
})
379
387
end
380
388
end
@@ -408,6 +416,7 @@ function Builder:build_lines(node)
408
416
idx = idx + 1
409
417
end
410
418
end
419
+ self :add_hidden_count_string (node )
411
420
end
412
421
413
422
--- @private
@@ -458,24 +467,10 @@ end
458
467
function Builder :build ()
459
468
self :build_header ()
460
469
self :build_lines ()
461
- self :build_root_hidden_count ()
462
470
self :sanitize_lines ()
463
471
return self
464
472
end
465
473
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
-
479
474
--- @param opts table
480
475
local setup_hidden_display_function = function (opts )
481
476
local hidden_display = opts .renderer .hidden_display
0 commit comments