am e0a42568: Merge "Fix a test."

* commit 'e0a425681c2902b463e57c55a4c4e9d6b3dc7311':
  Fix a test.
main
Jean Chalard 2014-02-12 21:22:57 -08:00 committed by Android Git Automerger
commit 2311c4b976
2 changed files with 31 additions and 19 deletions

View File

@ -1355,6 +1355,7 @@ public final class InputLogic {
final String previousWord = mLastComposedWord.mPrevWord; final String previousWord = mLastComposedWord.mPrevWord;
final CharSequence originallyTypedWord = mLastComposedWord.mTypedWord; final CharSequence originallyTypedWord = mLastComposedWord.mTypedWord;
final CharSequence committedWord = mLastComposedWord.mCommittedWord; final CharSequence committedWord = mLastComposedWord.mCommittedWord;
final String committedWordString = committedWord.toString();
final int cancelLength = committedWord.length(); final int cancelLength = committedWord.length();
// We want java chars, not codepoints for the following. // We want java chars, not codepoints for the following.
final int separatorLength = mLastComposedWord.mSeparatorString.length(); final int separatorLength = mLastComposedWord.mSeparatorString.length();
@ -1376,33 +1377,44 @@ public final class InputLogic {
if (!TextUtils.isEmpty(previousWord) && !TextUtils.isEmpty(committedWord)) { if (!TextUtils.isEmpty(previousWord) && !TextUtils.isEmpty(committedWord)) {
if (mSuggest != null) { if (mSuggest != null) {
mSuggest.mDictionaryFacilitator.cancelAddingUserHistory( mSuggest.mDictionaryFacilitator.cancelAddingUserHistory(
previousWord, committedWord.toString()); previousWord, committedWordString);
} }
} }
final String stringToCommit = originallyTypedWord + mLastComposedWord.mSeparatorString; final String stringToCommit = originallyTypedWord + mLastComposedWord.mSeparatorString;
final SpannableString textToCommit = new SpannableString(stringToCommit); final SpannableString textToCommit = new SpannableString(stringToCommit);
if (committedWord instanceof SpannableString) { if (committedWord instanceof SpannableString) {
final int lastCharIndex = textToCommit.length() - 1;
// Add the auto-correction to the list of suggestions.
textToCommit.setSpan(new SuggestionSpan(settingsValues.mLocale,
new String[] { committedWord.toString() }, 0 /* flags */),
0 /* start */, lastCharIndex /* end */, 0 /* flags */);
final SpannableString committedWordWithSuggestionSpans = (SpannableString)committedWord; final SpannableString committedWordWithSuggestionSpans = (SpannableString)committedWord;
final Object[] spans = committedWordWithSuggestionSpans.getSpans(0, final Object[] spans = committedWordWithSuggestionSpans.getSpans(0,
committedWord.length(), Object.class); committedWord.length(), Object.class);
final int lastCharIndex = textToCommit.length() - 1;
// We will collect all suggestions in the following array.
final ArrayList<String> suggestions = CollectionUtils.newArrayList();
// First, add the committed word to the list of suggestions.
suggestions.add(committedWordString);
for (final Object span : spans) { for (final Object span : spans) {
// Put all the spans in the original text on this new text. We could remove the // If this is a suggestion span, we check that the locale is the right one, and
// typed word from the suggestions, but we'd have to make more dynamic instanceof // that the word is not the committed word. That should mostly be the case.
// checks, to copy the span, copy all suggestions and attributes... And there is // Given this, we add it to the list of suggestions, otherwise we discard it.
// the risk to drop the originally typed string if there is a subtle bug. There is if (span instanceof SuggestionSpan) {
// still the committed auto-correction that we reverted from, which is not included final SuggestionSpan suggestionSpan = (SuggestionSpan)span;
// in the suggestions, that's why we added it with another call to setSpan a few if (!suggestionSpan.getLocale().equals(settingsValues.mLocale.toString())) {
// lines above. continue;
// The code that re-reads these spans already knows to do the right thing whether }
// the typed word is included or not. That should be enough. for (final String suggestion : suggestionSpan.getSuggestions()) {
textToCommit.setSpan(span, 0 /* start */, lastCharIndex /* end */, if (!suggestion.equals(committedWordString)) {
committedWordWithSuggestionSpans.getSpanFlags(span)); suggestions.add(suggestion);
}
}
} else {
// If this is not a suggestion span, we just add it as is.
textToCommit.setSpan(span, 0 /* start */, lastCharIndex /* end */,
committedWordWithSuggestionSpans.getSpanFlags(span));
}
} }
// Add the suggestion list to the list of suggestions.
textToCommit.setSpan(new SuggestionSpan(settingsValues.mLocale,
suggestions.toArray(new String[suggestions.size()]), 0 /* flags */),
0 /* start */, lastCharIndex /* end */, 0 /* flags */);
} }
if (settingsValues.mSpacingAndPunctuations.mCurrentLanguageHasSpaces) { if (settingsValues.mSpacingAndPunctuations.mCurrentLanguageHasSpaces) {
// For languages with spaces, we revert to the typed string, but the cursor is still // For languages with spaces, we revert to the typed string, but the cursor is still

View File

@ -80,8 +80,8 @@ public class BlueUnderlineTests extends InputTestsBase {
sleep(DELAY_TO_WAIT_FOR_UNDERLINE); sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
runMessages(); runMessages();
final SpanGetter suggestionSpan = new SpanGetter(mEditText.getText(), SuggestionSpan.class); final SpanGetter suggestionSpan = new SpanGetter(mEditText.getText(), SuggestionSpan.class);
assertEquals("show no blue underline after backspace, span start should be -1", assertFalse("show no blue underline after backspace, span start should be -1",
EXPECTED_SUGGESTION_SPAN_START, suggestionSpan.mStart); suggestionSpan.isAutoCorrectionIndicator());
final SpanGetter underlineSpan = new SpanGetter(mEditText.getText(), UnderlineSpan.class); final SpanGetter underlineSpan = new SpanGetter(mEditText.getText(), UnderlineSpan.class);
assertEquals("should be composing, so should have an underline span", assertEquals("should be composing, so should have an underline span",
EXPECTED_UNDERLINE_SPAN_START, underlineSpan.mStart); EXPECTED_UNDERLINE_SPAN_START, underlineSpan.mStart);