mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-29 20:59:00 +00:00
LibWeb: Fix nodesToRemove collecting traversal in Range::delete_contents
With this change children are no longer skipped in tree traversal when start node of range equals to end node of range. Fixes https://github.com/SerenityOS/serenity/issues/24036
This commit is contained in:
parent
cedf6dd2c3
commit
9540af6489
Notes:
sideshowbarker
2024-07-17 18:38:54 +09:00
Author: https://github.com/kalenikaliaksandr
Commit: 9540af6489
Pull-request: https://github.com/SerenityOS/serenity/pull/24038
Issue: https://github.com/SerenityOS/serenity/issues/24036
3 changed files with 19 additions and 1 deletions
1
Tests/LibWeb/Text/expected/DOM/Range-deleteContents.txt
Normal file
1
Tests/LibWeb/Text/expected/DOM/Range-deleteContents.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
before after
|
17
Tests/LibWeb/Text/input/DOM/Range-deleteContents.html
Normal file
17
Tests/LibWeb/Text/input/DOM/Range-deleteContents.html
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
before
|
||||||
|
<div id="for-deletion">
|
||||||
|
<div>should</div>
|
||||||
|
<div>be</div>
|
||||||
|
<div>gone</div>
|
||||||
|
</div>
|
||||||
|
after
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<script>
|
||||||
|
test(() => {
|
||||||
|
const element = document.getElementById("for-deletion");
|
||||||
|
const range = document.createRange();
|
||||||
|
range.selectNodeContents(element);
|
||||||
|
range.deleteContents();
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -1118,7 +1118,7 @@ WebIDL::ExceptionOr<void> Range::delete_contents()
|
||||||
|
|
||||||
// 4. Let nodes to remove be a list of all the nodes that are contained in this, in tree order, omitting any node whose parent is also contained in this.
|
// 4. Let nodes to remove be a list of all the nodes that are contained in this, in tree order, omitting any node whose parent is also contained in this.
|
||||||
JS::MarkedVector<Node*> nodes_to_remove(heap());
|
JS::MarkedVector<Node*> nodes_to_remove(heap());
|
||||||
for (Node const* node = start_container(); node != end_container()->next_in_pre_order(); node = node->next_in_pre_order()) {
|
for (Node const* node = start_container(); node != end_container()->next_sibling(); node = node->next_in_pre_order()) {
|
||||||
if (contains_node(*node) && (!node->parent_node() || !contains_node(*node->parent_node())))
|
if (contains_node(*node) && (!node->parent_node() || !contains_node(*node->parent_node())))
|
||||||
nodes_to_remove.append(const_cast<Node*>(node));
|
nodes_to_remove.append(const_cast<Node*>(node));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue