summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2023-05-23 07:42:01 +0200
committerAndreas Kling <kling@serenityos.org>2023-05-23 07:43:26 +0200
commite83681ee34a28861ac2c346580fe6d1959a80361 (patch)
tree0895218a3ea0bbac51ac02bfe12da3763356c90a /Userland/Libraries
parent80d6330a26f8c55a1bd38fd2f1388e50c0ae8977 (diff)
downloadserenity-e83681ee34a28861ac2c346580fe6d1959a80361.zip
LibWeb: Use the right DOM node when placing cursor on double-click
This fixes a null pointer dereference when double-clicking in text content on some pages.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibWeb/Page/EventHandler.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/Userland/Libraries/LibWeb/Page/EventHandler.cpp b/Userland/Libraries/LibWeb/Page/EventHandler.cpp
index 69f200d325..4fff7039ba 100644
--- a/Userland/Libraries/LibWeb/Page/EventHandler.cpp
+++ b/Userland/Libraries/LibWeb/Page/EventHandler.cpp
@@ -597,6 +597,8 @@ bool EventHandler::handle_doubleclick(CSSPixelPoint position, unsigned button, u
auto const& hit_layout_node = hit_paintable->layout_node();
if (!hit_layout_node.is_text_node())
return true;
+
+ auto& hit_dom_node = verify_cast<DOM::Text>(*hit_paintable->dom_node());
auto const& text_for_rendering = verify_cast<Layout::TextNode>(hit_layout_node).text_for_rendering();
int first_word_break_before = [&] {
@@ -619,9 +621,9 @@ bool EventHandler::handle_doubleclick(CSSPixelPoint position, unsigned button, u
return text_for_rendering.length();
}();
- m_browsing_context->set_cursor_position(DOM::Position(*paintable->dom_node(), first_word_break_after));
+ m_browsing_context->set_cursor_position(DOM::Position(hit_dom_node, first_word_break_after));
if (auto selection = node->document().get_selection()) {
- (void)selection->set_base_and_extent(*paintable->dom_node(), first_word_break_before, *paintable->dom_node(), first_word_break_after);
+ (void)selection->set_base_and_extent(hit_dom_node, first_word_break_before, hit_dom_node, first_word_break_after);
}
}
}