MCPcopy Create free account
hub / github.com/cogentcore/core / WalkUpParent

Method WalkUpParent

tree/nodebase.go:463–478  ·  view source on GitHub ↗

WalkUpParent calls the given function on all of the node's parents (but not the node itself), 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]. I

(fun func(n Node) bool)

Source from the content-addressed store, hash-verified

461// function returns [Break] and keeps walking if it returns [Continue]. It returns
462// whether walking was finished (false if it was aborted with [Break]).
463func (n *NodeBase) WalkUpParent(fun func(n Node) bool) bool {
464 if IsRoot(n) {
465 return true
466 }
467 cur := n.Parent
468 for {
469 if !fun(cur) { // false return means stop
470 return false
471 }
472 parent := cur.AsTree().Parent
473 if parent == nil || parent == cur { // prevent loops
474 return true
475 }
476 cur = parent
477 }
478}
479
480// WalkDown strategy: https://stackoverflow.com/questions/5278580/non-recursive-depth-first-search-algorithm
481

Callers 5

ParentLevelMethod · 0.95
RepoMethod · 0.80
OpenParentsMethod · 0.80
handleFocusEventMethod · 0.80
selectionMonitorMethod · 0.80

Calls 2

IsRootFunction · 0.85
AsTreeMethod · 0.65

Tested by

no test coverage detected