diff options
| author | Mateo Kuruk Miccino <mateomiccino@gmail.com> | 2021-02-28 16:52:04 -0300 |
|---|---|---|
| committer | Mateo Kuruk Miccino <mateomiccino@gmail.com> | 2021-03-01 08:38:08 -0300 |
| commit | a3db2fd46b220197a320152bab6aca145460ce57 (patch) | |
| tree | 66a98b406d32b077398f693d1e64f9fa05c3235c /scene/gui/line_edit.cpp | |
| parent | 870de12111e2b51bb2a8797c4ea0467b8d9dcb2a (diff) | |
| download | redot-engine-a3db2fd46b220197a320152bab6aca145460ce57.tar.gz | |
LineEdit: Now double click to select a word, and triple click to select all the content using the new TextServer
TextEdit: Update the method to search words with the new TextServer
Diffstat (limited to 'scene/gui/line_edit.cpp')
| -rw-r--r-- | scene/gui/line_edit.cpp | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index ba08aae8e3..3e8ebd2429 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -255,11 +255,30 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { selection.creating = true; } 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; + cursor_pos = selection.begin; + } else if (b->is_doubleclick()) { + // Double-click select word. + Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text_rid); + for (int i = 0; i < words.size(); i++) { + if (words[i].x < cursor_pos && words[i].y > cursor_pos) { + selection.enabled = true; + selection.begin = words[i].x; + selection.end = words[i].y; + selection.doubleclick = true; + selection.last_dblclk = OS::get_singleton()->get_ticks_msec(); + cursor_pos = selection.end; + break; + } + } + } } selection.drag_attempt = false; |
