Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5f859f20 authored by Jean Chalard's avatar Jean Chalard Committed by Android Git Automerger
Browse files

am 051ac1ef: Merge "Add a guard against OOB."

* commit '051ac1ef':
  Add a guard against OOB.
parents e8ff9e10 051ac1ef
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -2229,10 +2229,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
        final CharSequence textBeforeCursor = ic.getTextBeforeCursor(2, 0);
        // NOTE: This does not work with surrogate pairs. Hopefully when the keyboard is able to
        // enter surrogate pairs this code will have been removed.
        if (Keyboard.CODE_SPACE != textBeforeCursor.charAt(1)) {
            // We should not have come here if the text before the cursor is not a space.
            throw new RuntimeException("Tried to revert a swap of punctuation but we didn't "
        if (TextUtils.isEmpty(textBeforeCursor)
                || (Keyboard.CODE_SPACE != textBeforeCursor.charAt(1))) {
            // 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.");
            return false;
        }
        ic.beginBatchEdit();
        ic.deleteSurroundingText(2, 0);