MCPcopy Create free account
hub / github.com/Stranger6667/css-inline / append

Method append

css-inline/src/html/document.rs:317–335  ·  view source on GitHub ↗

Append a new child node to a parent node. If the parent node already has children. Before: [Parent] ↓ [Child1] <--> [Child2] <--> ... After: [Parent] ↓ [Child1] <--> [Child2] <--> [New] ... If the parent node has no children. Before: [Parent] After: [Parent] ↓ [New] So, [New} becomes the first child of [Parent].

(&mut self, parent: NodeId, node: NodeId)

Source from the content-addressed store, hash-verified

315 ///
316 /// So, [New} becomes the first child of [Parent].
317 pub(super) fn append(&mut self, parent: NodeId, node: NodeId) {
318 // Detach `node` from its current parent (if any)
319 self.detach(node);
320
321 // Set `node` parent to the specified parent
322 self[node].parent = Some(parent);
323
324 if let Some(last_child) = self[parent].last_child.take() {
325 // Connect `node` with the last child (if any) by adding `node` after it
326 self[node].previous_sibling = Some(last_child);
327 self[last_child].next_sibling = Some(node);
328 } else {
329 // No last child - it becomes the first child
330 self[parent].first_child = Some(node);
331 }
332
333 // Now, `node` is the last child of the new parent
334 self[parent].last_child = Some(node);
335 }
336
337 /// Insert a new node right before a given sibling node.
338 ///

Callers 3

reparent_childrenMethod · 0.45
test_insert_beforeFunction · 0.45
test_appendFunction · 0.45

Calls 1

detachMethod · 0.80

Tested by 2

test_insert_beforeFunction · 0.36
test_appendFunction · 0.36