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

Function MoveToParent

tree/admin.go:77–86  ·  view source on GitHub ↗

MoveToParent removes the given node from its current parent and adds it as a child of the given new parent. The old and new parents can be in different trees (or not).

(child Node, parent Node)

Source from the content-addressed store, hash-verified

75// and adds it as a child of the given new parent.
76// The old and new parents can be in different trees (or not).
77func MoveToParent(child Node, parent Node) {
78 oldParent := child.AsTree().Parent
79 if oldParent != nil {
80 idx := IndexOf(oldParent.AsTree().Children, child)
81 if idx >= 0 {
82 oldParent.AsTree().Children = slices.Delete(oldParent.AsTree().Children, idx, idx+1)
83 }
84 }
85 parent.AsTree().AddChild(child)
86}
87
88// ParentByType returns the first parent of the given node that is
89// of the given type, if any such node exists.

Callers

nothing calls this directly

Calls 4

IndexOfFunction · 0.85
AsTreeMethod · 0.65
DeleteMethod · 0.65
AddChildMethod · 0.45

Tested by

no test coverage detected