diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2020-12-16 14:15:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-16 14:15:06 +0100 |
commit | 41a8bc40b9a3a00ee0ae76543b0b9a075e604cbd (patch) | |
tree | d6795d784213f88cc9a34273dbfed0139250cf70 | |
parent | 98b8279df830255803d977f0f6617e0727579f98 (diff) | |
parent | efeb9e4d0810f25c3fd52e3e0672cb6c01ecdbaf (diff) |
Merge pull request #44423 from naithar/fix/text-edit-cursor
[4.0] TextEdit virtual keyboard cursor fix
-rw-r--r-- | scene/gui/text_edit.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 1d65abc95f..f3569f9ce3 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1654,16 +1654,19 @@ void TextEdit::_notification(int p_what) { } if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD) && virtual_keyboard_enabled) { - String text = _base_get_text(0, 0, selection.selecting_line, selection.selecting_column); - int cursor_start = text.length(); + int cursor_start = -1; int cursor_end = -1; - if (selection.active) { - String selected_text = _base_get_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column); + if (!selection.active) { + String full_text = _base_get_text(0, 0, cursor.line, cursor.column); - if (selected_text.length() > 0) { - cursor_end = cursor_start + selected_text.length(); - } + cursor_start = full_text.length(); + } else { + String pre_text = _base_get_text(0, 0, selection.from_line, selection.from_column); + String post_text = _base_get_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column); + + cursor_start = pre_text.length(); + cursor_end = cursor_start + post_text.length(); } DisplayServer::get_singleton()->virtual_keyboard_show(get_text(), get_global_rect(), true, -1, cursor_start, cursor_end); |