@@ -276,25 +276,29 @@ public void showKeyboard(String p_existing_text, VirtualKeyboardType p_type, int
276276 return ;
277277 }
278278
279+ int cursorStart = p_cursor_start ;
280+ int cursorEnd = p_cursor_end ;
279281 int maxInputLength = (p_max_input_length <= 0 ) ? Integer .MAX_VALUE : p_max_input_length ;
280- if (p_cursor_start == -1 ) { // cursor position not given
282+ if (cursorStart == -1 ) { // cursor position not given
281283 this .mOriginText = p_existing_text ;
282284 this .mMaxInputLength = maxInputLength ;
283- } else if (p_cursor_end == -1 ) { // not text selection
284- this .mOriginText = p_existing_text .substring (0 , p_cursor_start );
285- this .mMaxInputLength = maxInputLength - (p_existing_text .length () - p_cursor_start );
285+ } else if (cursorEnd == -1 ) { // not text selection
286+ cursorStart = Math .min (p_existing_text .length (), cursorStart );
287+ this .mOriginText = p_existing_text .substring (0 , cursorStart );
288+ this .mMaxInputLength = maxInputLength - (p_existing_text .length () - cursorStart );
286289 } else {
287- this .mOriginText = p_existing_text .substring (0 , p_cursor_end );
288- this .mMaxInputLength = maxInputLength - (p_existing_text .length () - p_cursor_end );
290+ cursorEnd = Math .min (p_existing_text .length (), cursorEnd );
291+ this .mOriginText = p_existing_text .substring (0 , cursorEnd );
292+ this .mMaxInputLength = maxInputLength - (p_existing_text .length () - cursorEnd );
289293 }
290294
291295 this .mKeyboardType = p_type ;
292296
293297 final Message msg = new Message ();
294298 msg .what = HANDLER_OPEN_IME_KEYBOARD ;
295299 msg .obj = this ;
296- msg .arg1 = p_cursor_start ;
297- msg .arg2 = p_cursor_end ;
300+ msg .arg1 = cursorStart ;
301+ msg .arg2 = cursorEnd ;
298302 sHandler .sendMessage (msg );
299303 }
300304
0 commit comments