mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Merge pull request #110611 from m4gr3d/fix_show_keyboard_crash
Fix the bug causing `java.lang.StringIndexOutOfBoundsException` crashes when showing the virtual keyboard
This commit is contained in:
commit
f84123d20e
1 changed files with 12 additions and 8 deletions
|
@ -276,16 +276,20 @@ public class GodotEditText extends EditText {
|
|||
return;
|
||||
}
|
||||
|
||||
int cursorStart = p_cursor_start;
|
||||
int cursorEnd = p_cursor_end;
|
||||
int maxInputLength = (p_max_input_length <= 0) ? Integer.MAX_VALUE : p_max_input_length;
|
||||
if (p_cursor_start == -1) { // cursor position not given
|
||||
if (cursorStart == -1) { // cursor position not given
|
||||
this.mOriginText = p_existing_text;
|
||||
this.mMaxInputLength = maxInputLength;
|
||||
} else if (p_cursor_end == -1) { // not text selection
|
||||
this.mOriginText = p_existing_text.substring(0, p_cursor_start);
|
||||
this.mMaxInputLength = maxInputLength - (p_existing_text.length() - p_cursor_start);
|
||||
} else if (cursorEnd == -1) { // not text selection
|
||||
cursorStart = Math.min(p_existing_text.length(), cursorStart);
|
||||
this.mOriginText = p_existing_text.substring(0, cursorStart);
|
||||
this.mMaxInputLength = maxInputLength - (p_existing_text.length() - cursorStart);
|
||||
} else {
|
||||
this.mOriginText = p_existing_text.substring(0, p_cursor_end);
|
||||
this.mMaxInputLength = maxInputLength - (p_existing_text.length() - p_cursor_end);
|
||||
cursorEnd = Math.min(p_existing_text.length(), cursorEnd);
|
||||
this.mOriginText = p_existing_text.substring(0, cursorEnd);
|
||||
this.mMaxInputLength = maxInputLength - (p_existing_text.length() - cursorEnd);
|
||||
}
|
||||
|
||||
this.mKeyboardType = p_type;
|
||||
|
@ -293,8 +297,8 @@ public class GodotEditText extends EditText {
|
|||
final Message msg = new Message();
|
||||
msg.what = HANDLER_OPEN_IME_KEYBOARD;
|
||||
msg.obj = this;
|
||||
msg.arg1 = p_cursor_start;
|
||||
msg.arg2 = p_cursor_end;
|
||||
msg.arg1 = cursorStart;
|
||||
msg.arg2 = cursorEnd;
|
||||
sHandler.sendMessage(msg);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue