summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMelissa Geels <spansjh@gmail.com>2021-08-11 09:54:44 +0200
committerMelissa Geels <spansjh@gmail.com>2021-08-11 21:49:26 +0200
commit408401a64241423cae66ee5087bc50f2ba66aa3d (patch)
tree78bfa328b834ef197d230aabf7755c363b10d55a
parent974cc68fb420768a244c14dfd7a59da73f2330bd (diff)
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.
-rw-r--r--scene/gui/text_edit.cpp6
-rw-r--r--scene/gui/text_edit.h1
2 files changed, 6 insertions, 1 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 1b3935dd25..3c6034f938 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -2246,7 +2246,10 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
selection.selecting_column = col;
}
- if (!mb->is_double_click() && (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_double_click() && (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 = SelectionMode::SELECTION_MODE_LINE;
_update_selection_mode_line();
@@ -2256,6 +2259,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
selection.selecting_mode = SelectionMode::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 9e6dedb267..c5853786cf 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -308,6 +308,7 @@ private:
String lookup_symbol_word;
uint64_t last_dblclk = 0;
+ Vector2 last_dblclk_pos;
Timer *idle_detect;
Timer *click_select_held;