1
0
Fork 0

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
This commit is contained in:
Mateo Kuruk Miccino 2021-02-28 16:52:04 -03:00
parent 870de12111
commit a3db2fd46b
3 changed files with 34 additions and 23 deletions

View File

@ -255,11 +255,30 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
selection.creating = true; selection.creating = true;
} else { } else {
if (b->is_doubleclick() && selecting_enabled) { if (selecting_enabled) {
selection.enabled = true; if (!b->is_doubleclick() && (OS::get_singleton()->get_ticks_msec() - selection.last_dblclk) < 600) {
selection.begin = 0; // Triple-click select all.
selection.end = text.length(); selection.enabled = true;
selection.doubleclick = 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; selection.drag_attempt = false;

View File

@ -136,6 +136,7 @@ private:
bool creating = false; bool creating = false;
bool doubleclick = false; bool doubleclick = false;
bool drag_attempt = false; bool drag_attempt = false;
uint64_t last_dblclk = 0;
} selection; } selection;
struct TextOperation { struct TextOperation {

View File

@ -412,25 +412,16 @@ void TextEdit::_update_selection_mode_word() {
_get_mouse_pos(Point2i(mp.x, mp.y), row, col); _get_mouse_pos(Point2i(mp.x, mp.y), row, col);
String line = text[row]; String line = text[row];
int beg = CLAMP(col, 0, line.length()); int cursor_pos = CLAMP(col, 0, line.length());
// If its the first selection and on whitespace make sure we grab the word instead. int beg = cursor_pos;
if (!selection.active) {
while (beg > 0 && line[beg] <= 32) {
beg--;
}
}
int end = beg; int end = beg;
bool symbol = beg < line.length() && _is_symbol(line[beg]); Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(row)->get_rid());
for (int i = 0; i < words.size(); i++) {
// Get the word end and begin points. if (words[i].x < cursor_pos && words[i].y > cursor_pos) {
while (beg > 0 && line[beg - 1] > 32 && (symbol == _is_symbol(line[beg - 1]))) { beg = words[i].x;
beg--; end = words[i].y;
} break;
while (end < line.length() && line[end + 1] > 32 && (symbol == _is_symbol(line[end + 1]))) { }
end++;
}
if (end < line.length()) {
end += 1;
} }
// Initial selection. // Initial selection.