mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
LibWeb: Update implementation of Range::partially_contains_node()
This accurately reflects the spec it's implementing. This algorithm is used in 5 spots in the spec but the old buggy behavior was never triggered: * In both ::extract() and ::clone_the_contents(), invocations to this method are guarded by a check to see if the start node is the inclusive ancestor of the end node, or vice versa - effectively resulting in the inequality checks to be accidentally correct. * In ::surround_contents(), we forego the usage of this algorithm as stated in the spec, and instead use a correct and more optimized version that simply compares the start and end nodes. A lot of words to say: no functional changes :^)
This commit is contained in:
parent
36190e3baf
commit
e6334d217b
Notes:
github-actions[bot]
2025-01-09 10:16:54 +00:00
Author: https://github.com/gmta Commit: https://github.com/LadybirdBrowser/ladybird/commit/e6334d217b8 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3193 Reviewed-by: https://github.com/tcl3 ✅
1 changed files with 4 additions and 7 deletions
|
@ -2,7 +2,7 @@
|
|||
* Copyright (c) 2020, the SerenityOS developers.
|
||||
* Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
|
||||
* Copyright (c) 2022-2023, Andreas Kling <andreas@ladybird.org>
|
||||
* Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org>
|
||||
* Copyright (c) 2024-2025, Jelle Raaijmakers <jelle@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -807,12 +807,9 @@ bool Range::contains_node(GC::Ref<Node> node) const
|
|||
// https://dom.spec.whatwg.org/#partially-contained
|
||||
bool Range::partially_contains_node(GC::Ref<Node> node) const
|
||||
{
|
||||
// A node is partially contained in a live range if it’s an inclusive ancestor of the live range’s start node but not its end node, or vice versa.
|
||||
if (node->is_inclusive_ancestor_of(m_start_container) && node != m_end_container)
|
||||
return true;
|
||||
if (node->is_inclusive_ancestor_of(m_end_container) && node != m_start_container)
|
||||
return true;
|
||||
return false;
|
||||
// A node is partially contained in a live range if it’s an inclusive ancestor of the live range’s start node but
|
||||
// not its end node, or vice versa.
|
||||
return node->is_inclusive_ancestor_of(m_start_container) != node->is_inclusive_ancestor_of(m_end_container);
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-range-insertnode
|
||||
|
|
Loading…
Add table
Reference in a new issue