fix: expand and collapse whole folder groups (#2380)

* fix: expand and collapse whole folder groups

* refactor: rename some usages of `next`

---------

Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
Danie-1 2023-08-26 05:44:38 +01:00 committed by GitHub
parent b144b33390
commit 00741206c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -74,11 +74,21 @@ end
-- If node is grouped, return the last node in the group. Otherwise, return the given node.
function M.get_last_group_node(node)
local next = node
while next.group_next do
next = next.group_next
local next_node = node
while next_node.group_next do
next_node = next_node.group_next
end
return next
return next_node
end
function M.get_all_nodes_in_group(node)
local next_node = utils.get_parent_of_group(node)
local nodes = {}
while next_node do
table.insert(nodes, next_node)
next_node = next_node.group_next
end
return nodes
end
function M.expand_or_collapse(node)
@ -90,8 +100,10 @@ function M.expand_or_collapse(node)
core.get_explorer():expand(node)
end
node = M.get_last_group_node(node)
node.open = not node.open
local open = not M.get_last_group_node(node).open
for _, n in ipairs(M.get_all_nodes_in_group(node)) do
n.open = open
end
renderer.draw()
end