am e5cdcaff: Fix a race condition, take 2.

* commit 'e5cdcaff658f5366621115a728cb683eab5fda0a':
  Fix a race condition, take 2.
main
Jean Chalard 2014-01-08 01:43:00 -08:00 committed by Android Git Automerger
commit 3d38accd1f
2 changed files with 18 additions and 5 deletions

View File

@ -685,6 +685,10 @@ public final class RichInputConnection {
&& !settingsValues.isWordConnector(codePointBeforeCursor)) {
return true;
}
return isCursorFollowedByWordCharacter(settingsValues);
}
public boolean isCursorFollowedByWordCharacter(final SettingsValues settingsValues) {
final CharSequence after = getTextAfterCursor(1, 0);
if (!TextUtils.isEmpty(after) && !settingsValues.isWordSeparator(after.charAt(0))
&& !settingsValues.isWordConnector(after.charAt(0))) {

View File

@ -813,7 +813,8 @@ public final class InputLogic {
}
}
if (settingsValues.isSuggestionStripVisible()
&& settingsValues.mCurrentLanguageHasSpaces) {
&& settingsValues.mCurrentLanguageHasSpaces
&& !mConnection.isCursorFollowedByWordCharacter(settingsValues)) {
restartSuggestionsOnWordTouchedByCursor(settingsValues,
deleteCountAtStart - mDeleteCount /* offset */,
true /* includeResumedWordInSuggestions */, keyboardSwitcher);
@ -1113,11 +1114,19 @@ public final class InputLogic {
keyboardSwitcher.getKeyboard());
mWordComposer.setCursorPositionWithinWord(
typedWord.codePointCount(0, numberOfCharsInWordBeforeCursor));
// TODO: Change these two lines to setComposingRegion(cursorPosition,
// TODO: Change these lines to setComposingRegion(cursorPosition,
// cursorPosition + range.getNumberOfCharsInWordAfterCursor());
mConnection.deleteSurroundingText(numberOfCharsInWordBeforeCursor,
typedWord.length() - numberOfCharsInWordBeforeCursor);
if (0 != offset) {
// Backspace was pressed. We are at the end of a word, and we don't know the cursor
// position for sure, so use relative methods.
mConnection.deleteSurroundingText(numberOfCharsInWordBeforeCursor, 0);
mConnection.setComposingText(typedWord, 1);
} else {
// This is recorrection. The cursor position is reasonably reliable, and the cursor
// may be in the middle of a word so use setComposingRegion.
mConnection.setComposingRegion(expectedCursorPosition - numberOfCharsInWordBeforeCursor,
expectedCursorPosition + range.getNumberOfCharsInWordAfterCursor());
}
if (suggestions.isEmpty()) {
// We come here if there weren't any suggestion spans on this word. We will try to
// compute suggestions for it instead.