Skip to content

Commit 579fc7b

Browse files
committed
tidy expand all
1 parent f09c518 commit 579fc7b

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

lua/nvim-tree/actions/tree/modifiers/expand-all.lua

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ local function to_lookup_table(list)
1717
return table
1818
end
1919

20-
---@param node Node
20+
---@param node DirectoryNode
2121
local function expand(node)
22-
if node:is(DirectoryNode) then
23-
node = node:last_group_node()
24-
end
22+
node = node:last_group_node()
2523
node.open = true
2624
if #node.nodes == 0 then
2725
core.get_explorer():expand(node)
@@ -40,6 +38,7 @@ end
4038
local function gen_iterator()
4139
local expansion_count = 0
4240

41+
---@param parent DirectoryNode
4342
return function(parent)
4443
if parent.parent and parent.nodes and not parent.open then
4544
expansion_count = expansion_count + 1
@@ -48,12 +47,14 @@ local function gen_iterator()
4847

4948
Iterator.builder(parent.nodes)
5049
:hidden()
50+
---@param node DirectoryNode
5151
:applier(function(node)
5252
if should_expand(expansion_count, node) then
5353
expansion_count = expansion_count + 1
5454
expand(node)
5555
end
5656
end)
57+
---@param node DirectoryNode
5758
:recursor(function(node)
5859
return expansion_count < M.MAX_FOLDER_DISCOVERY and (node.group_next and { node.group_next } or (node.open and node.nodes))
5960
end)
@@ -65,11 +66,16 @@ local function gen_iterator()
6566
end
6667
end
6768

69+
---Expand the directory node or the root
6870
---@param node Node
6971
function M.fn(node)
7072
local explorer = core.get_explorer()
71-
node = node.nodes and node or explorer
72-
if gen_iterator()(node) then
73+
local parent = node:as(DirectoryNode) or explorer
74+
if not parent then
75+
return
76+
end
77+
78+
if gen_iterator()(parent) then
7379
notify.warn("expansion iteration was halted after " .. M.MAX_FOLDER_DISCOVERY .. " discovered folders")
7480
end
7581
if explorer then

lua/nvim-tree/node/directory.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ function DirectoryNode:refresh()
133133
end
134134

135135
-- If node is grouped, return the last node in the group. Otherwise, return the given node.
136-
---@return Node
136+
---@return DirectoryNode
137137
function DirectoryNode:last_group_node()
138138
return self.group_next and self.group_next:last_group_node() or self
139139
end

0 commit comments

Comments
 (0)