MCPcopy
hub / github.com/g3n/engine / AddAt

Method AddAt

core/node.go:321–338  ·  view source on GitHub ↗

AddAt adds the specified node to the list of children at the specified index and sets its parent pointer. If the specified node had a parent, the specified node is removed from the original parent's list of children.

(idx int, ichild INode)

Source from the content-addressed store, hash-verified

319// AddAt adds the specified node to the list of children at the specified index and sets its parent pointer.
320// If the specified node had a parent, the specified node is removed from the original parent's list of children.
321func (n *Node) AddAt(idx int, ichild INode) *Node {
322
323 // Validate position
324 if idx < 0 || idx > len(n.children) {
325 panic("Node.AddAt: invalid position")
326 }
327
328 setParent(n.GetINode(), ichild)
329
330 // Insert child in the specified position
331 n.children = append(n.children, nil)
332 copy(n.children[idx+1:], n.children[idx:])
333 n.children[idx] = ichild
334
335 n.Dispatch(OnDescendant, nil)
336
337 return n
338}
339
340// setParent is used by Add and AddAt.
341// It verifies that the node is not being added to itself and sets the parent pointer of the specified node.

Callers

nothing calls this directly

Calls 3

GetINodeMethod · 0.95
setParentFunction · 0.85
DispatchMethod · 0.65

Tested by

no test coverage detected