insertAfter<T> static method
Rebuild nodes, inserting toAdd immediately after the node afterId
at whatever depth it lives.
Implementation
static List<TreeNode<T>> insertAfter<T>(List<TreeNode<T>> nodes, TreeNodeId afterId, TreeNode<T> toAdd) {
final out = <TreeNode<T>>[];
for (final n in nodes) {
out.add(n.children.isEmpty ? n : n.copyWith(children: insertAfter<T>(n.children, afterId, toAdd)));
if (n.id == afterId) out.add(toAdd);
}
return out;
}