mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 05:39:11 +00:00
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.
This commit is contained in:
parent
698a95d2de
commit
e5d1261640
Notes:
sideshowbarker
2024-07-17 08:38:37 +09:00
Author: https://github.com/tcl3
Commit: e5d1261640
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/359
1 changed files with 11 additions and 4 deletions
|
@ -546,15 +546,22 @@ bool EventHandler::handle_mousemove(CSSPixelPoint viewport_position, CSSPixelPoi
|
|||
}
|
||||
if (m_in_mouse_selection) {
|
||||
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()) {
|
||||
m_navigable->set_cursor_position(DOM::Position::create(realm, *hit->dom_node(), *start_index));
|
||||
if (auto selection = document.get_selection()) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
if (should_set_cursor_position)
|
||||
m_navigable->set_cursor_position(DOM::Position::create(realm, *hit->dom_node(), *start_index));
|
||||
|
||||
document.navigable()->set_needs_display();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue