toggleNodeRecursive method
- String nodeId
Recursively toggle a node and all its descendant submodules.
When expanding: toggles the node open, then recursively expands every expandable child all the way down the hierarchy. When collapsing: recursively collapses all expanded descendants first, then collapses this node so re-expanding starts fresh.
When the node is partially expanded (blocks-only mode), promotes it to fully expanded and recursively expands all descendants — the user intent of SHIFT+click is "open everything".
Returns true if the initial toggle was successful.
Implementation
bool toggleNodeRecursive(String nodeId) {
final node = nodeMap[nodeId];
if (node == null) {
return false;
}
final wasPartiallyExpanded = node.isPartiallyExpanded;
if (wasPartiallyExpanded) {
// Partially expanded (blocks-only) — promote to full expansion.
// Clear partial state, then toggle open and expand descendants.
node
..partialChildIds = null
..partialHyperedgeIds = null;
if (!toggleNode(nodeId)) {
return false;
}
_expandDescendants(node);
} else if (node.isExpandable) {
// Expanding: toggle open, then expand all descendants.
if (!toggleNode(nodeId)) {
return false;
}
_expandDescendants(node);
} else if (node.isExpanded) {
// Collapsing: first collapse all expanded descendants, then this.
_collapseDescendants(node);
toggleNode(nodeId);
} else {
return false;
}
return true;
}