Merge pull request #52979 from jmb462/fix-lineedit-double-clic-selection

This commit is contained in:
Rémi Verschelde 2021-09-27 00:08:20 +02:00 committed by GitHub
commit 3221fb4618
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 7 deletions

View File

@ -260,24 +260,29 @@ void LineEdit::gui_input(const Ref<InputEvent> &p_event) {
} else { } else {
if (selecting_enabled) { if (selecting_enabled) {
if (!b->is_double_click() && (OS::get_singleton()->get_ticks_msec() - selection.last_dblclk) < 600) { const int triple_click_timeout = 600;
const int triple_click_tolerance = 5;
const bool is_triple_click = !b->is_double_click() && (OS::get_singleton()->get_ticks_msec() - last_dblclk) < triple_click_timeout && b->get_position().distance_to(last_dblclk_pos) < triple_click_tolerance;
if (is_triple_click && text.length()) {
// Triple-click select all. // Triple-click select all.
selection.enabled = true; selection.enabled = true;
selection.begin = 0; selection.begin = 0;
selection.end = text.length(); selection.end = text.length();
selection.double_click = true; selection.double_click = true;
selection.last_dblclk = 0; last_dblclk = 0;
caret_column = selection.begin; caret_column = selection.begin;
} else if (b->is_double_click()) { } else if (b->is_double_click()) {
// Double-click select word. // Double-click select word.
last_dblclk = OS::get_singleton()->get_ticks_msec();
last_dblclk_pos = b->get_position();
Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text_rid); Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text_rid);
for (int i = 0; i < words.size(); i++) { for (int i = 0; i < words.size(); i++) {
if (words[i].x < caret_column && words[i].y > caret_column) { if ((words[i].x < caret_column && words[i].y > caret_column) || (i == words.size() - 1 && caret_column == words[i].y)) {
selection.enabled = true; selection.enabled = true;
selection.begin = words[i].x; selection.begin = words[i].x;
selection.end = words[i].y; selection.end = words[i].y;
selection.double_click = true; selection.double_click = true;
selection.last_dblclk = OS::get_singleton()->get_ticks_msec();
caret_column = selection.end; caret_column = selection.end;
break; break;
} }

View File

@ -136,7 +136,6 @@ private:
bool creating = false; bool creating = false;
bool double_click = false; bool double_click = false;
bool drag_attempt = false; bool drag_attempt = false;
uint64_t last_dblclk = 0;
} selection; } selection;
struct TextOperation { struct TextOperation {
@ -153,6 +152,9 @@ private:
bool pressing_inside = false; bool pressing_inside = false;
} clear_button_status; } clear_button_status;
uint64_t last_dblclk = 0;
Vector2 last_dblclk_pos;
bool caret_blink_enabled = false; bool caret_blink_enabled = false;
bool caret_force_displayed = false; bool caret_force_displayed = false;
bool draw_caret = true; bool draw_caret = true;

View File

@ -3689,7 +3689,7 @@ void TextEdit::select_word_under_caret() {
int end = 0; int end = 0;
const Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(caret.line)->get_rid()); const Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(caret.line)->get_rid());
for (int i = 0; i < words.size(); i++) { for (int i = 0; i < words.size(); i++) {
if (words[i].x <= caret.column && words[i].y >= caret.column) { if ((words[i].x < caret.column && words[i].y > caret.column) || (i == words.size() - 1 && caret.column == words[i].y)) {
begin = words[i].x; begin = words[i].x;
end = words[i].y; end = words[i].y;
break; break;
@ -5411,7 +5411,7 @@ void TextEdit::_update_selection_mode_word() {
int end = beg; int end = beg;
Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(line)->get_rid()); Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(line)->get_rid());
for (int i = 0; i < words.size(); i++) { for (int i = 0; i < words.size(); i++) {
if (words[i].x < caret_pos && words[i].y > caret_pos) { if ((words[i].x < caret_pos && words[i].y > caret_pos) || (i == words.size() - 1 && caret_pos == words[i].y)) {
beg = words[i].x; beg = words[i].x;
end = words[i].y; end = words[i].y;
break; break;