LibWeb: Use correct boundaries in Selection::collapse_to_start/end()

We were using the anchor_node() as the boundary point node when
collapsing a selection, but the spec tells us to use the start and end
boundary point nodes.
This commit is contained in:
Jelle Raaijmakers 2024-12-20 11:34:49 +01:00 committed by Jelle Raaijmakers
commit 2052792663
Notes: github-actions[bot] 2024-12-21 18:18:09 +00:00
3 changed files with 35 additions and 4 deletions

View file

@ -239,8 +239,8 @@ WebIDL::ExceptionOr<void> Selection::collapse_to_start()
auto new_range = DOM::Range::create(*m_document);
// 3. Set the start both its start and end to the start of this's range
TRY(new_range->set_start(*anchor_node(), m_range->start_offset()));
TRY(new_range->set_end(*anchor_node(), m_range->start_offset()));
TRY(new_range->set_start(*m_range->start_container(), m_range->start_offset()));
TRY(new_range->set_end(*m_range->start_container(), m_range->start_offset()));
// 4. Then set this's range to the newly-created range.
set_range(new_range);
@ -259,8 +259,8 @@ WebIDL::ExceptionOr<void> Selection::collapse_to_end()
auto new_range = DOM::Range::create(*m_document);
// 3. Set the start both its start and end to the start of this's range
TRY(new_range->set_start(*anchor_node(), m_range->end_offset()));
TRY(new_range->set_end(*anchor_node(), m_range->end_offset()));
TRY(new_range->set_start(*m_range->end_container(), m_range->end_offset()));
TRY(new_range->set_end(*m_range->end_container(), m_range->end_offset()));
// 4. Then set this's range to the newly-created range.
set_range(new_range);