Add a guard against OOB.
...and avoid crashing in one case where the application may change the text while we are typing. Bug: 5685922 Change-Id: I4a22c63168986f43ac84f512aaa4267023d536e3
This commit is contained in:
parent
61b31a646e
commit
8be16f78b1
1 changed files with 7 additions and 3 deletions
|
@ -2229,10 +2229,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
final CharSequence textBeforeCursor = ic.getTextBeforeCursor(2, 0);
|
final CharSequence textBeforeCursor = ic.getTextBeforeCursor(2, 0);
|
||||||
// NOTE: This does not work with surrogate pairs. Hopefully when the keyboard is able to
|
// NOTE: This does not work with surrogate pairs. Hopefully when the keyboard is able to
|
||||||
// enter surrogate pairs this code will have been removed.
|
// enter surrogate pairs this code will have been removed.
|
||||||
if (Keyboard.CODE_SPACE != textBeforeCursor.charAt(1)) {
|
if (TextUtils.isEmpty(textBeforeCursor)
|
||||||
// We should not have come here if the text before the cursor is not a space.
|
|| (Keyboard.CODE_SPACE != textBeforeCursor.charAt(1))) {
|
||||||
throw new RuntimeException("Tried to revert a swap of punctuation but we didn't "
|
// We may only come here if the application is changing the text while we are typing.
|
||||||
|
// This is quite a broken case, but not logically impossible, so we shouldn't crash,
|
||||||
|
// but some debugging log may be in order.
|
||||||
|
Log.d(TAG, "Tried to revert a swap of punctuation but we didn't "
|
||||||
+ "find a space just before the cursor.");
|
+ "find a space just before the cursor.");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
ic.beginBatchEdit();
|
ic.beginBatchEdit();
|
||||||
ic.deleteSurroundingText(2, 0);
|
ic.deleteSurroundingText(2, 0);
|
||||||
|
|
Loading…
Reference in a new issue