mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-13 13:02:28 +00:00
LibWeb: Set both start and end in Selection::extend
This commit is contained in:
parent
93927d8243
commit
f41cbfa2a9
Notes:
github-actions[bot]
2024-10-13 07:47:56 +00:00
Author: https://github.com/Gingeh
Commit: f41cbfa2a9
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1765
1 changed files with 4 additions and 2 deletions
|
@ -265,8 +265,8 @@ WebIDL::ExceptionOr<void> Selection::collapse_to_end()
|
||||||
// https://w3c.github.io/selection-api/#dom-selection-extend
|
// https://w3c.github.io/selection-api/#dom-selection-extend
|
||||||
WebIDL::ExceptionOr<void> Selection::extend(JS::NonnullGCPtr<DOM::Node> node, unsigned offset)
|
WebIDL::ExceptionOr<void> Selection::extend(JS::NonnullGCPtr<DOM::Node> node, unsigned offset)
|
||||||
{
|
{
|
||||||
// 1. If node's root is not the document associated with this, abort these steps.
|
// 1. If the document associated with this is not a shadow-including inclusive ancestor of node, abort these steps.
|
||||||
if (&node->root() != m_document.ptr())
|
if (!m_document->is_shadow_including_inclusive_ancestor_of(node))
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
// 2. If this is empty, throw an InvalidStateError exception and abort these steps.
|
// 2. If this is empty, throw an InvalidStateError exception and abort these steps.
|
||||||
|
@ -287,9 +287,11 @@ WebIDL::ExceptionOr<void> Selection::extend(JS::NonnullGCPtr<DOM::Node> node, un
|
||||||
// 5. If node's root is not the same as the this's range's root, set the start newRange's start and end to newFocus.
|
// 5. If node's root is not the same as the this's range's root, set the start newRange's start and end to newFocus.
|
||||||
if (&node->root() != &m_range->start_container()->root()) {
|
if (&node->root() != &m_range->start_container()->root()) {
|
||||||
TRY(new_range->set_start(new_focus_node, new_focus_offset));
|
TRY(new_range->set_start(new_focus_node, new_focus_offset));
|
||||||
|
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.
|
// 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 (old_anchor_node.is_before(new_focus_node) || &old_anchor_node == new_focus_node.ptr()) {
|
||||||
|
TRY(new_range->set_start(old_anchor_node, old_anchor_offset));
|
||||||
TRY(new_range->set_end(new_focus_node, new_focus_offset));
|
TRY(new_range->set_end(new_focus_node, new_focus_offset));
|
||||||
}
|
}
|
||||||
// 7. Otherwise, set the start newRange's start to newFocus, then set its end to oldAnchor.
|
// 7. Otherwise, set the start newRange's start to newFocus, then set its end to oldAnchor.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue