LibWeb: Add Range::for_each_contained()

This centralizes the logic for iterating over a Range's contained nodes.
This commit is contained in:
Jelle Raaijmakers 2025-01-09 10:20:07 +01:00 committed by Andreas Kling
commit 4323669939
Notes: github-actions[bot] 2025-01-10 22:39:13 +00:00
5 changed files with 44 additions and 26 deletions

View file

@ -578,10 +578,11 @@ String Range::to_string() const
}
// 4. Append the concatenation of the data of all Text nodes that are contained in this, in tree order, to s.
for (GC::Ptr<Node> node = start_container(); node != end_container()->next_sibling(); node = node->next_in_pre_order()) {
if (is<Text>(*node) && contains_node(*node))
for_each_contained([&](GC::Ref<DOM::Node> node) {
if (is<Text>(*node))
builder.append(static_cast<Text const&>(*node).data());
}
return IterationDecision::Continue;
});
// 5. If thiss end node is a Text node, then append the substring of that nodes data from its start until thiss end offset to s.
if (is<Text>(*end_container())) {