mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-17 07:50:04 +00:00
LibWeb: Use correct boundary point comparison in Selection.extend
Previously Selection.extend() used only the relative node order to decide which direction to extend the selection. This leads to incorrect behaviour if both the existing and new boundary points are within the same DOM node and the selection direction is reversed. This change fixes all the failing subtests in the WPT extend-* test suites.
This commit is contained in:
parent
ee35e93eb2
commit
18ade57ae9
Notes:
github-actions[bot]
2024-10-13 13:12:39 +00:00
Author: https://github.com/jdmnd
Commit: 18ade57ae9
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1768
5 changed files with 47 additions and 2 deletions
|
@ -290,7 +290,7 @@ WebIDL::ExceptionOr<void> Selection::extend(JS::NonnullGCPtr<DOM::Node> node, un
|
|||
TRY(new_range->set_end(new_focus_node, new_focus_offset));
|
||||
}
|
||||
// 6. Otherwise, if oldAnchor is before or equal to newFocus, set the start newRange's start to oldAnchor, then set its end to newFocus.
|
||||
else if (old_anchor_node.is_before(new_focus_node) || &old_anchor_node == new_focus_node.ptr()) {
|
||||
else if (position_of_boundary_point_relative_to_other_boundary_point(old_anchor_node, old_anchor_offset, new_focus_node, new_focus_offset) != DOM::RelativeBoundaryPointPosition::After) {
|
||||
TRY(new_range->set_start(old_anchor_node, old_anchor_offset));
|
||||
TRY(new_range->set_end(new_focus_node, new_focus_offset));
|
||||
}
|
||||
|
@ -304,7 +304,7 @@ WebIDL::ExceptionOr<void> Selection::extend(JS::NonnullGCPtr<DOM::Node> node, un
|
|||
set_range(new_range);
|
||||
|
||||
// 9. If newFocus is before oldAnchor, set this's direction to backwards. Otherwise, set it to forwards.
|
||||
if (new_focus_node->is_before(old_anchor_node)) {
|
||||
if (position_of_boundary_point_relative_to_other_boundary_point(new_focus_node, new_focus_offset, old_anchor_node, old_anchor_offset) == DOM::RelativeBoundaryPointPosition::Before) {
|
||||
m_direction = Direction::Backwards;
|
||||
} else {
|
||||
m_direction = Direction::Forwards;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue