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

Method detach

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

Detach a node from its siblings and its parent. Before: [Parent] ↓ ... [Previous] <--> [Node] <--> [Next] ... After: [Parent] ↓ ... [Previous] <--> [Next] ...

(&mut self, node: NodeId)

Source from the content-addressed store, hash-verified

251 /// ↓
252 /// ... [Previous] <--> [Next] ...
253 pub(super) fn detach(&mut self, node: NodeId) {
254 // Save references to the parent and sibling nodes of the node being detached.
255 let (parent, previous_sibling, next_sibling) = {
256 let node = &mut self[node];
257 (
258 node.parent.take(),
259 node.previous_sibling.take(),
260 node.next_sibling.take(),
261 )
262 };
263
264 if let Some(next_sibling) = next_sibling {
265 // Point next sibling one step back to bypass the detached node
266 self[next_sibling].previous_sibling = previous_sibling;
267 } else if let Some(parent) = parent {
268 // No next sibling - this node was the last child of the parent node, now the previous
269 // sibling becomes the last child
270 self[parent].last_child = previous_sibling;
271 }
272
273 if let Some(previous_sibling) = previous_sibling {
274 // Point the previous sibling one step forward to bypass the detached node
275 self[previous_sibling].next_sibling = next_sibling;
276 } else if let Some(parent) = parent {
277 // No previous sibling - this node was the first child of the parent node, now the next
278 // sibling becomes the first child
279 self[parent].first_child = next_sibling;
280 }
281 }
282
283 /// Remove all the children from node and append them to `new_parent`.
284 pub(super) fn reparent_children(&mut self, node: NodeId, new_parent: NodeId) {

Callers 5

detach_nodeMethod · 0.80
appendMethod · 0.80
insert_beforeMethod · 0.80
test_edit_documentFunction · 0.80
remove_from_parentMethod · 0.80

Calls

no outgoing calls

Tested by 1

test_edit_documentFunction · 0.64