Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] LineEdit: Now double click to select a word, and triple click to sele… #46527

Merged
merged 1 commit into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions scene/gui/line_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,34 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {

} else {

if (b->is_doubleclick() && selecting_enabled) {

selection.enabled = true;
selection.begin = 0;
selection.end = text.length();
selection.doubleclick = true;
if (selecting_enabled) {
if (!b->is_doubleclick() && (OS::get_singleton()->get_ticks_msec() - selection.last_dblclk) < 600) {
// Triple-click select all.
selection.enabled = true;
selection.begin = 0;
selection.end = text.length();
selection.doubleclick = true;
selection.last_dblclk = 0;
} else if (b->is_doubleclick()) {
// Double-click select word.
selection.enabled = true;
int beg = cursor_pos;
int end = beg;
bool symbol = beg < text.length() && is_symbol(text[beg]);
while (beg > 0 && text[beg - 1] > 32 && (symbol == is_symbol(text[beg - 1]))) {
beg--;
}
while (end < text.length() && text[end + 1] > 32 && (symbol == is_symbol(text[end + 1]))) {
end++;
}
if (end < text.length()) {
end += 1;
}
selection.begin = beg;
selection.end = end;
selection.doubleclick = true;
selection.last_dblclk = OS::get_singleton()->get_ticks_msec();
}
}

selection.drag_attempt = false;
Expand Down
1 change: 1 addition & 0 deletions scene/gui/line_edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class LineEdit : public Control {
bool creating;
bool doubleclick;
bool drag_attempt;
uint64_t last_dblclk = 0;
} selection;

struct TextOperation {
Expand Down