diff --git a/Tests/LibWeb/Text/expected/collapse-selection-inside-shadow-root.txt b/Tests/LibWeb/Text/expected/collapse-selection-inside-shadow-root.txt new file mode 100644 index 00000000000..607651bc0a9 --- /dev/null +++ b/Tests/LibWeb/Text/expected/collapse-selection-inside-shadow-root.txt @@ -0,0 +1,6 @@ + null +null +button1 +button1 +button2 +button2 diff --git a/Tests/LibWeb/Text/input/collapse-selection-inside-shadow-root.html b/Tests/LibWeb/Text/input/collapse-selection-inside-shadow-root.html new file mode 100644 index 00000000000..a7633c5ed1c --- /dev/null +++ b/Tests/LibWeb/Text/input/collapse-selection-inside-shadow-root.html @@ -0,0 +1,35 @@ + + +
+ diff --git a/Userland/Libraries/LibWeb/Selection/Selection.cpp b/Userland/Libraries/LibWeb/Selection/Selection.cpp index 0fed976d158..5977ac0db84 100644 --- a/Userland/Libraries/LibWeb/Selection/Selection.cpp +++ b/Userland/Libraries/LibWeb/Selection/Selection.cpp @@ -183,8 +183,8 @@ WebIDL::ExceptionOr Selection::collapse(JS::GCPtr node, unsigne return WebIDL::IndexSizeError::create(realm(), "Selection.collapse() with offset longer than node's length"_fly_string); } - // 3. If node's root is not the document associated with this, abort these steps. - if (&node->root() != m_document.ptr()) + // 3. If document associated with this is not a shadow-including inclusive ancestor of node, abort these steps. + if (!m_document->is_shadow_including_inclusive_ancestor_of(*node)) return {}; // 4. Otherwise, let newRange be a new range.