diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index dead530326e101e65de3193f563125af7cdd732b..c9311a6d880107e247a5b7bf168624a415be274c 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -2746,6 +2746,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final TextRange range = mConnection.getWordRangeAtCursor(currentSettings.mWordSeparators, 0 /* additionalPrecedingWordsCount */); if (null == range) return; // Happens if we don't have an input connection at all + if (range.length() <= 0) return; // Race condition. No text to resume on, so bail out. // If for some strange reason (editor bug or so) we measure the text before the cursor as // longer than what the entire text is supposed to be, the safe thing to do is bail out. final int numberOfCharsInWordBeforeCursor = range.getNumberOfCharsInWordBeforeCursor(); diff --git a/java/src/com/android/inputmethod/latin/utils/TextRange.java b/java/src/com/android/inputmethod/latin/utils/TextRange.java index 5793e4170b21398d954d963c5ce70a0605d79182..48b443ddd957756d161c2685017a6453b1692f72 100644 --- a/java/src/com/android/inputmethod/latin/utils/TextRange.java +++ b/java/src/com/android/inputmethod/latin/utils/TextRange.java @@ -40,6 +40,10 @@ public final class TextRange { return mWordAtCursorEndIndex - mCursorIndex; } + public int length() { + return mWord.length(); + } + /** * Gets the suggestion spans that are put squarely on the word, with the exact start * and end of the span matching the boundaries of the word.