diff --git a/Tests/LibWeb/Text/expected/is-collapsed.txt b/Tests/LibWeb/Text/expected/is-collapsed.txt new file mode 100644 index 00000000000..7ef22e9a431 --- /dev/null +++ b/Tests/LibWeb/Text/expected/is-collapsed.txt @@ -0,0 +1 @@ +PASS diff --git a/Tests/LibWeb/Text/input/is-collapsed.html b/Tests/LibWeb/Text/input/is-collapsed.html new file mode 100644 index 00000000000..5a12704953d --- /dev/null +++ b/Tests/LibWeb/Text/input/is-collapsed.html @@ -0,0 +1,27 @@ + +

Simply selectable

+ + diff --git a/Userland/Libraries/LibWeb/Selection/Selection.cpp b/Userland/Libraries/LibWeb/Selection/Selection.cpp index e783a1533df..741a674228a 100644 --- a/Userland/Libraries/LibWeb/Selection/Selection.cpp +++ b/Userland/Libraries/LibWeb/Selection/Selection.cpp @@ -96,7 +96,10 @@ bool Selection::is_collapsed() const { // The attribute must return true if and only if the anchor and focus are the same // (including if both are null). Otherwise it must return false. - return const_cast(this)->anchor_node() == const_cast(this)->focus_node(); + if (!m_range) + return true; + return const_cast(this)->anchor_node() == const_cast(this)->focus_node() + && m_range->start_offset() == m_range->end_offset(); } // https://w3c.github.io/selection-api/#dom-selection-rangecount