From 39cba61c2dfa8f3510bcd1a34232fd206c270b87 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 16 Aug 2023 15:10:18 +0100 Subject: [PATCH] LibGUI: Fall back to words when double-clicking TextEditor with spans If we double-click on a TextEditor that has spans, but the click itself was not on a span, fall back to the without-spans behavior. Previously the cursor would instead jump to the end of the document. --- Userland/Libraries/LibGUI/TextEditor.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp index 20d9e1ae2d..69bbed2d32 100644 --- a/Userland/Libraries/LibGUI/TextEditor.cpp +++ b/Userland/Libraries/LibGUI/TextEditor.cpp @@ -265,19 +265,23 @@ void TextEditor::doubleclick_event(MouseEvent& event) m_in_drag_select = false; auto position = text_position_at(event.position()); + bool got_selection = false; if (m_substitution_code_point.has_value()) { // NOTE: If we substitute the code points, we don't want double clicking to only select a single word, since // whitespace isn't visible anymore. m_selection = document().range_for_entire_line(position.line()); + got_selection = true; } else if (document().has_spans()) { for (auto& span : document().spans()) { if (span.range.contains(position)) { m_selection = span.range; + got_selection = true; break; } } - } else { + } + if (!got_selection) { m_selection.set_start(document().first_word_break_before(position, false)); m_selection.set_end(document().first_word_break_after(position)); }