From c79041344d7f9957bf810cd4db5330d8006ef0e3 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Wed, 5 Jun 2024 17:20:58 +0100 Subject: [PATCH] LibWeb: Ensure anchor node is not null when extending selection Previously, clicking while holding shift without having previously made any text selection would cause a crash. --- Userland/Libraries/LibWeb/Page/EventHandler.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/Page/EventHandler.cpp b/Userland/Libraries/LibWeb/Page/EventHandler.cpp index 93c7e90f75a..831c8a271eb 100644 --- a/Userland/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Userland/Libraries/LibWeb/Page/EventHandler.cpp @@ -433,8 +433,9 @@ bool EventHandler::handle_mousedown(CSSPixelPoint viewport_position, CSSPixelPoi auto& realm = document->realm(); m_navigable->set_cursor_position(DOM::Position::create(realm, *paintable->dom_node(), result->index_in_node)); if (auto selection = document->get_selection()) { - if (modifiers & KeyModifier::Mod_Shift) { - (void)selection->set_base_and_extent(*selection->anchor_node(), selection->anchor_offset(), *paintable->dom_node(), result->index_in_node); + auto anchor_node = selection->anchor_node(); + if (anchor_node && modifiers & KeyModifier::Mod_Shift) { + (void)selection->set_base_and_extent(*anchor_node, selection->anchor_offset(), *paintable->dom_node(), result->index_in_node); } else { (void)selection->set_base_and_extent(*paintable->dom_node(), result->index_in_node, *paintable->dom_node(), result->index_in_node); }