Fix a bug that happens upon a race condition

Bug: 10848621
Change-Id: If5ff7f001e69af005a5ff9ab3e9f630b88a0a858
main
Jean Chalard 2013-09-20 18:21:10 +09:00
parent 3de1aca289
commit be3be424a3
2 changed files with 5 additions and 0 deletions

View File

@ -2746,6 +2746,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final TextRange range = mConnection.getWordRangeAtCursor(currentSettings.mWordSeparators, final TextRange range = mConnection.getWordRangeAtCursor(currentSettings.mWordSeparators,
0 /* additionalPrecedingWordsCount */); 0 /* additionalPrecedingWordsCount */);
if (null == range) return; // Happens if we don't have an input connection at all 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 // 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. // longer than what the entire text is supposed to be, the safe thing to do is bail out.
final int numberOfCharsInWordBeforeCursor = range.getNumberOfCharsInWordBeforeCursor(); final int numberOfCharsInWordBeforeCursor = range.getNumberOfCharsInWordBeforeCursor();

View File

@ -40,6 +40,10 @@ public final class TextRange {
return mWordAtCursorEndIndex - mCursorIndex; return mWordAtCursorEndIndex - mCursorIndex;
} }
public int length() {
return mWord.length();
}
/** /**
* Gets the suggestion spans that are put squarely on the word, with the exact start * 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. * and end of the span matching the boundaries of the word.