From d132ce54e1e90c5932090911f80f5a7d58c9b24e Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 12 Jan 2023 20:27:16 +0100 Subject: [PATCH] LibWeb: Don't mark layout tree as selected when selection is zero-length --- .../LibWeb/Layout/InitialContainingBlock.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/Layout/InitialContainingBlock.cpp b/Userland/Libraries/LibWeb/Layout/InitialContainingBlock.cpp index df74329fbc0..90504c4559c 100644 --- a/Userland/Libraries/LibWeb/Layout/InitialContainingBlock.cpp +++ b/Userland/Libraries/LibWeb/Layout/InitialContainingBlock.cpp @@ -79,7 +79,23 @@ void InitialContainingBlock::recompute_selection_states() auto* start_container = range->start_container(); auto* end_container = range->end_container(); - // 3. If the selection starts and ends in the same text node, mark it as StartAndEnd and return. + // 3. If the selection starts and ends in the same node: + if (start_container == end_container) { + // 1. If the selection starts and ends at the same offset, return. + if (range->start_offset() == range->end_offset()) { + // NOTE: A zero-length selection should not be visible. + return; + } + + // 2. If it's a text node, mark it as StartAndEnd and return. + if (is(*start_container)) { + if (auto* layout_node = start_container->layout_node()) { + layout_node->set_selection_state(SelectionState::StartAndEnd); + } + return; + } + } + if (start_container == end_container && is(*start_container)) { if (auto* layout_node = start_container->layout_node()) { layout_node->set_selection_state(SelectionState::StartAndEnd);