1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:27:35 +00:00

LibWeb: Implement the (string) replace all operations for Node

This commit is contained in:
Luke Wilde 2021-09-06 01:25:58 +01:00 committed by Andreas Kling
parent 67c73ddd59
commit d36838d050
2 changed files with 30 additions and 0 deletions

View file

@ -718,4 +718,31 @@ bool Node::is_shadow_including_inclusive_ancestor_of(Node const& other) const
return other.is_shadow_including_inclusive_descendant_of(*this);
}
// https://dom.spec.whatwg.org/#concept-node-replace-all
void Node::replace_all(RefPtr<Node> node)
{
// FIXME: Let removedNodes be parents children. (Current unused so not included)
// FIXME: Let addedNodes be the empty set. (Currently unused so not included)
// FIXME: If node is a DocumentFragment node, then set addedNodes to nodes children.
// FIXME: Otherwise, if node is non-null, set addedNodes to « node ».
remove_all_children(true);
if (node)
insert_before(*node, nullptr, true);
// FIXME: If either addedNodes or removedNodes is not empty, then queue a tree mutation record for parent with addedNodes, removedNodes, null, and null.
}
// https://dom.spec.whatwg.org/#string-replace-all
void Node::string_replace_all(String const& string)
{
RefPtr<Node> node;
if (!string.is_empty())
node = make_ref_counted<Text>(document(), string);
replace_all(node);
}
}