LibWeb: Don't mark layout tree as selected when selection is zero-length

This commit is contained in:
Andreas Kling 2023-01-12 20:27:16 +01:00
parent 2eaebdea5b
commit d132ce54e1
Notes: sideshowbarker 2024-07-17 01:47:36 +09:00

View file

@ -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);