From ac40f5bb759030b972801eb428b55b616ded4788 Mon Sep 17 00:00:00 2001 From: Melissa Geels Date: Wed, 11 Aug 2021 09:54:44 +0200 Subject: [PATCH] Triple click in text editor now uses last mouse position for validity Previously, you would be able to double click a word, followed by single-clicking another word on the same line, which would select the entire line. Now, it will only select the whole line if the mouse position has remained the same after the double click. This mimicks the behavior in most third party text editors. Fixes #51312. (cherry picked from commit 408401a64241423cae66ee5087bc50f2ba66aa3d) --- scene/gui/text_edit.cpp | 6 +++++- scene/gui/text_edit.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 408d193ccf4..465ca542deb 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -2477,7 +2477,10 @@ void TextEdit::_gui_input(const Ref &p_gui_input) { selection.selecting_column = col; } - if (!mb->is_doubleclick() && (OS::get_singleton()->get_ticks_msec() - last_dblclk) < 600 && cursor.line == prev_line) { + const int triple_click_timeout = 600; + const int triple_click_tolerance = 5; + + if (!mb->is_doubleclick() && (OS::get_singleton()->get_ticks_msec() - last_dblclk) < triple_click_timeout && mb->get_position().distance_to(last_dblclk_pos) < triple_click_tolerance) { // Triple-click select line. selection.selecting_mode = Selection::MODE_LINE; _update_selection_mode_line(); @@ -2487,6 +2490,7 @@ void TextEdit::_gui_input(const Ref &p_gui_input) { selection.selecting_mode = Selection::MODE_WORD; _update_selection_mode_word(); last_dblclk = OS::get_singleton()->get_ticks_msec(); + last_dblclk_pos = mb->get_position(); } update(); diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index f73dea0d8ed..97b2f91e295 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -403,6 +403,7 @@ private: String highlighted_word; uint64_t last_dblclk; + Vector2 last_dblclk_pos; Timer *idle_detect; Timer *click_select_held;