diff --git a/Libraries/LibWeb/Selection/Selection.cpp b/Libraries/LibWeb/Selection/Selection.cpp index 3577056a07d..e43d658c441 100644 --- a/Libraries/LibWeb/Selection/Selection.cpp +++ b/Libraries/LibWeb/Selection/Selection.cpp @@ -239,8 +239,8 @@ WebIDL::ExceptionOr 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 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); diff --git a/Tests/LibWeb/Text/expected/selection-collapseToEnd.txt b/Tests/LibWeb/Text/expected/selection-collapseToEnd.txt new file mode 100644 index 00000000000..bfbc9dfc85b --- /dev/null +++ b/Tests/LibWeb/Text/expected/selection-collapseToEnd.txt @@ -0,0 +1,2 @@ +[object HTMLDivElement] 0 [object HTMLUListElement] 3 +[object HTMLUListElement] 3 [object HTMLUListElement] 3 diff --git a/Tests/LibWeb/Text/input/selection-collapseToEnd.html b/Tests/LibWeb/Text/input/selection-collapseToEnd.html new file mode 100644 index 00000000000..623f1d150c9 --- /dev/null +++ b/Tests/LibWeb/Text/input/selection-collapseToEnd.html @@ -0,0 +1,29 @@ + +
+ Well +
    +
  • Hello
  • +
  • Friends
  • +
  • !
  • +
+
+