From 94230acf287a9c2b613549a052e6209953d7a202 Mon Sep 17 00:00:00 2001 From: HolonProduction Date: Mon, 2 Sep 2024 14:03:45 +0200 Subject: [PATCH] LibWeb: Update `Selection.collapse` algorithm --- .../collapse-selection-inside-shadow-root.txt | 6 ++++ ...collapse-selection-inside-shadow-root.html | 35 +++++++++++++++++++ .../Libraries/LibWeb/Selection/Selection.cpp | 4 +-- 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/collapse-selection-inside-shadow-root.txt create mode 100644 Tests/LibWeb/Text/input/collapse-selection-inside-shadow-root.html 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.