@@ -2,6 +2,10 @@ local notify = require("nvim-tree.notify")
22local utils = require (" nvim-tree.utils" )
33local view = require (" nvim-tree.view" )
44
5+ local DirectoryLinkNode = require (" nvim-tree.node.directory-link" )
6+ local DirectoryNode = require (" nvim-tree.node.directory" )
7+ local FileLinkNode = require (" nvim-tree.node.file-link" )
8+
59local DecoratorBookmarks = require (" nvim-tree.renderer.decorator.bookmarks" )
610local DecoratorCopied = require (" nvim-tree.renderer.decorator.copied" )
711local DecoratorCut = require (" nvim-tree.renderer.decorator.cut" )
@@ -341,19 +345,21 @@ function Builder:add_highlights(node)
341345 return icon_hl_group , name_hl_group
342346end
343347
348+ --- Insert node line into self.lines, calling Builder:build_lines for each directory
344349--- @private
345- function Builder :build_line (node , idx , num_children )
350+ --- @param node Node
351+ --- @param idx integer line number starting at 1
352+ --- @param siblings integer of node
353+ function Builder :build_line (node , idx , siblings )
346354 -- various components
347- local indent_markers = pad .get_indent_markers (self .depth , idx , num_children , node , self .markers )
355+ local indent_markers = pad .get_indent_markers (self .depth , idx , siblings , node , self .markers )
348356 local arrows = pad .get_arrows (node )
349357
350358 -- main components
351- local is_folder = node .nodes ~= nil
352- local is_symlink = node .link_to ~= nil
353359 local icon , name
354- if is_folder then
360+ if node : is ( DirectoryNode ) then
355361 icon , name = self :build_folder (node )
356- elseif is_symlink then
362+ elseif node : is ( DirectoryLinkNode ) or node : is ( FileLinkNode ) then
357363 icon , name = self :build_symlink (node )
358364 else
359365 icon , name = self :build_file (node )
@@ -369,11 +375,13 @@ function Builder:build_line(node, idx, num_children)
369375
370376 self .index = self .index + 1
371377
372- node = node :last_group_node ()
373- if node .open then
374- self .depth = self .depth + 1
375- self :build_lines (node )
376- self .depth = self .depth - 1
378+ if node :is (DirectoryNode ) then
379+ node = node :last_group_node ()
380+ if node .open then
381+ self .depth = self .depth + 1
382+ self :build_lines (node )
383+ self .depth = self .depth - 1
384+ end
377385 end
378386end
379387
@@ -403,8 +411,11 @@ function Builder:add_hidden_count_string(node, idx, num_children)
403411 end
404412end
405413
414+ --- Number of visible nodes
406415--- @private
407- function Builder :get_nodes_number (nodes )
416+ --- @param nodes Node[]
417+ --- @return integer
418+ function Builder :num_visible (nodes )
408419 if not self .explorer .live_filter .filter then
409420 return # nodes
410421 end
@@ -423,12 +434,12 @@ function Builder:build_lines(node)
423434 if not node then
424435 node = self .explorer
425436 end
426- local num_children = self :get_nodes_number (node .nodes )
437+ local siblings = self :num_visible (node .nodes )
427438 local idx = 1
428439 for _ , n in ipairs (node .nodes ) do
429440 if not n .hidden then
430441 self :build_signs (n )
431- self :build_line (n , idx , num_children )
442+ self :build_line (n , idx , siblings )
432443 idx = idx + 1
433444 end
434445 end
0 commit comments