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:
@@ -74,11 +74,21 @@ end
|
|||||||
|
|
||||||
-- If node is grouped, return the last node in the group. Otherwise, return the given node.
|
-- If node is grouped, return the last node in the group. Otherwise, return the given node.
|
||||||
function M.get_last_group_node(node)
|
function M.get_last_group_node(node)
|
||||||
local next = node
|
local next_node = node
|
||||||
while next.group_next do
|
while next_node.group_next do
|
||||||
next = next.group_next
|
next_node = next_node.group_next
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
function M.expand_or_collapse(node)
|
function M.expand_or_collapse(node)
|
||||||
@@ -90,8 +100,10 @@ function M.expand_or_collapse(node)
|
|||||||
core.get_explorer():expand(node)
|
core.get_explorer():expand(node)
|
||||||
end
|
end
|
||||||
|
|
||||||
node = M.get_last_group_node(node)
|
local open = not M.get_last_group_node(node).open
|
||||||
node.open = not node.open
|
for _, n in ipairs(M.get_all_nodes_in_group(node)) do
|
||||||
|
n.open = open
|
||||||
|
end
|
||||||
|
|
||||||
renderer.draw()
|
renderer.draw()
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user