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

Method FindPath

tree/nodebase.go:272–286  ·  view source on GitHub ↗

FindPath returns the node at the given path from this node. FindPath only works correctly when names are unique. The given path must be consistent with the format produced by [NodeBase.PathFrom]. There is also support for index-based access (ie: [0] for the first child) for cases where indexes are m

(path string)

Source from the content-addressed store, hash-verified

270// are more useful than names. It returns nil if no node is found
271// at the given path.
272func (n *NodeBase) FindPath(path string) Node {
273 curn := n.This
274 pels := strings.Split(strings.Trim(strings.TrimSpace(path), "\""), "/")
275 for _, pe := range pels {
276 if len(pe) == 0 {
277 continue
278 }
279 idx := findPathChild(curn, UnescapePathName(pe))
280 if idx < 0 {
281 return nil
282 }
283 curn = curn.AsTree().Children[idx]
284 }
285 return curn
286}
287
288// findPathChild finds the child with the given string representation in [NodeBase.FindPath].
289func findPathChild(n Node, child string) int {

Callers 12

TestNodeEscapePathsFunction · 0.95
pasteCheckExistingMethod · 0.80
pasteCopyFilesMethod · 0.80
DropDeleteSourceMethod · 0.80
InitMethod · 0.80
OpenURLMethod · 0.80
dropDeleteSourceSyncMethod · 0.80
DropDeleteSourceMethod · 0.80
childByLabelCanFocusFunction · 0.80
DoActMethod · 0.80
SplitsMethod · 0.80
TabsMethod · 0.80

Calls 4

findPathChildFunction · 0.85
UnescapePathNameFunction · 0.85
SplitMethod · 0.80
AsTreeMethod · 0.65

Tested by 1

TestNodeEscapePathsFunction · 0.76