diff options
author | Andreas Kling <kling@serenityos.org> | 2023-01-12 20:27:16 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-01-12 20:27:16 +0100 |
commit | d132ce54e1e90c5932090911f80f5a7d58c9b24e (patch) | |
tree | d12b9d8249e40932f7b0ad0efdceace1163c80e6 /Userland/Libraries/LibWeb | |
parent | 2eaebdea5b59e1ed9004b1342fae345e318c27b4 (diff) | |
download | serenity-d132ce54e1e90c5932090911f80f5a7d58c9b24e.zip |
LibWeb: Don't mark layout tree as selected when selection is zero-length
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/InitialContainingBlock.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/InitialContainingBlock.cpp b/Userland/Libraries/LibWeb/Layout/InitialContainingBlock.cpp index df74329fbc..90504c4559 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<DOM::Text>(*start_container)) { + if (auto* layout_node = start_container->layout_node()) { + layout_node->set_selection_state(SelectionState::StartAndEnd); + } + return; + } + } + if (start_container == end_container && is<DOM::Text>(*start_container)) { if (auto* layout_node = start_container->layout_node()) { layout_node->set_selection_state(SelectionState::StartAndEnd); |