mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-02-04 06:23:45 +00:00
Merge pull request #1320 from lightpanda-io/fix-replaceChildren
remove children from previous parent
This commit is contained in:
@@ -2188,10 +2188,6 @@ pub fn insertAllChildrenBefore(self: *Page, fragment: *Node, target: *Node, ref_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _appendNode(self: *Page, comptime from_parser: bool, parent: *Node, child: *Node, opts: InsertNodeOpts) !void {
|
|
||||||
self._insertNodeRelative(from_parser, parent, child, .append, opts);
|
|
||||||
}
|
|
||||||
|
|
||||||
const InsertNodeRelative = union(enum) {
|
const InsertNodeRelative = union(enum) {
|
||||||
append,
|
append,
|
||||||
after: *Node,
|
after: *Node,
|
||||||
|
|||||||
@@ -156,6 +156,12 @@ pub fn replaceChildren(self: *DocumentFragment, nodes: []const Node.NodeOrText,
|
|||||||
const parent_is_connected = parent.isConnected();
|
const parent_is_connected = parent.isConnected();
|
||||||
for (nodes) |node_or_text| {
|
for (nodes) |node_or_text| {
|
||||||
const child = try node_or_text.toNode(page);
|
const child = try node_or_text.toNode(page);
|
||||||
|
|
||||||
|
// If the new children has already a parent, remove from it.
|
||||||
|
if (child._parent) |p| {
|
||||||
|
page.removeNode(p, child, .{ .will_be_reconnected = true });
|
||||||
|
}
|
||||||
|
|
||||||
try page.appendNode(parent, child, .{ .child_already_connected = parent_is_connected });
|
try page.appendNode(parent, child, .{ .child_already_connected = parent_is_connected });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user