WalkUp calls the given function on the node and all of its parents, sequentially in the current goroutine (generally necessary for going up, which is typically quite fast anyway). It stops walking if the function returns [Break] and keeps walking if it returns [Continue]. It returns whether walking
(fun func(n Node) bool)
| 442 | // returns [Break] and keeps walking if it returns [Continue]. It returns |
| 443 | // whether walking was finished (false if it was aborted with [Break]). |
| 444 | func (n *NodeBase) WalkUp(fun func(n Node) bool) bool { |
| 445 | cur := n.This |
| 446 | for { |
| 447 | if !fun(cur) { // false return means stop |
| 448 | return false |
| 449 | } |
| 450 | parent := cur.AsTree().Parent |
| 451 | if parent == nil || parent == cur { // prevent loops |
| 452 | return true |
| 453 | } |
| 454 | cur = parent |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | // WalkUpParent calls the given function on all of the node's parents (but not |
| 459 | // the node itself), sequentially in the current goroutine (generally necessary |