Ver código fonte

LibWeb: Don't update selection if start and end node roots differ

This allows selection to work within shadow roots and prevents the
selection being cleared if the mouse moves outside of the current
document or shadow root.
Tim Ledbetter 1 ano atrás
pai
commit
e5d1261640
1 arquivos alterados com 11 adições e 4 exclusões
  1. 11 4
      Userland/Libraries/LibWeb/Page/EventHandler.cpp

+ 11 - 4
Userland/Libraries/LibWeb/Page/EventHandler.cpp

@@ -546,15 +546,22 @@ bool EventHandler::handle_mousemove(CSSPixelPoint viewport_position, CSSPixelPoi
         }
         }
         if (m_in_mouse_selection) {
         if (m_in_mouse_selection) {
             auto hit = paint_root()->hit_test(position, Painting::HitTestType::TextCursor);
             auto hit = paint_root()->hit_test(position, Painting::HitTestType::TextCursor);
+            auto should_set_cursor_position = true;
             if (start_index.has_value() && hit.has_value() && hit->dom_node()) {
             if (start_index.has_value() && hit.has_value() && hit->dom_node()) {
-                m_navigable->set_cursor_position(DOM::Position::create(realm, *hit->dom_node(), *start_index));
                 if (auto selection = document.get_selection()) {
                 if (auto selection = document.get_selection()) {
                     auto anchor_node = selection->anchor_node();
                     auto anchor_node = selection->anchor_node();
-                    if (anchor_node)
-                        (void)selection->set_base_and_extent(*anchor_node, selection->anchor_offset(), *hit->paintable->dom_node(), hit->index_in_node);
-                    else
+                    if (anchor_node) {
+                        if (&anchor_node->root() == &hit->dom_node()->root())
+                            (void)selection->set_base_and_extent(*anchor_node, selection->anchor_offset(), *hit->paintable->dom_node(), hit->index_in_node);
+                        else
+                            should_set_cursor_position = false;
+                    } else {
                         (void)selection->set_base_and_extent(*hit->paintable->dom_node(), hit->index_in_node, *hit->paintable->dom_node(), hit->index_in_node);
                         (void)selection->set_base_and_extent(*hit->paintable->dom_node(), hit->index_in_node, *hit->paintable->dom_node(), hit->index_in_node);
+                    }
                 }
                 }
+                if (should_set_cursor_position)
+                    m_navigable->set_cursor_position(DOM::Position::create(realm, *hit->dom_node(), *start_index));
+
                 document.navigable()->set_needs_display();
                 document.navigable()->set_needs_display();
             }
             }
         }
         }