From 1d2e4f9dccfba925dda75a1ded569c3b62f639ed Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 24 Jan 2014 22:33:44 +0900 Subject: [PATCH] [IL103] Save the typed word separately in SuggestedWords. This helps managing the cases where the typed word is not in the suggestions. This happens during recorrection. Bug: 8636060 Change-Id: I6784feb793cae96272a7f1d123a0e3bbb8f03143 --- .../android/inputmethod/latin/LatinIME.java | 3 ++- .../inputmethod/latin/SuggestedWords.java | 25 ++++++++++++++++--- .../latin/inputlogic/InputLogic.java | 5 ++-- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index e8ea5e39d..46f2b3c2b 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1538,6 +1538,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } } + // [IL] TODO: remove the second argument public void unsetIsAutoCorrectionIndicatorOnAndCallShowSuggestionStrip( final SuggestedWords suggestedWords, final String typedWord) { // Note that it's very important here that suggestedWords.mWillAutoCorrect is false. @@ -1547,7 +1548,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // the text to adapt it. // TODO: remove mIsAutoCorrectionIndicatorOn (see comment on definition) mInputLogic.mIsAutoCorrectionIndicatorOn = false; - mHandler.showSuggestionStripWithTypedWord(suggestedWords, typedWord); + mHandler.showSuggestionStripWithTypedWord(suggestedWords, suggestedWords.mTypedWord); } // TODO: Make this private diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index 982a97a5e..dbaf822e4 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -68,6 +68,21 @@ public final class SuggestedWords { final boolean isObsoleteSuggestions, final boolean isPrediction, final int sequenceNumber) { + this(suggestedWordInfoList, + suggestedWordInfoList.isEmpty() ? null + : suggestedWordInfoList.get(INDEX_OF_TYPED_WORD).mWord, + typedWordValid, willAutoCorrect, isPunctuationSuggestions, + isObsoleteSuggestions, isPrediction, sequenceNumber); + } + + public SuggestedWords(final ArrayList suggestedWordInfoList, + final String typedWord, + final boolean typedWordValid, + final boolean willAutoCorrect, + final boolean isPunctuationSuggestions, + final boolean isObsoleteSuggestions, + final boolean isPrediction, + final int sequenceNumber) { mSuggestedWordInfoList = suggestedWordInfoList; mTypedWordValid = typedWordValid; mWillAutoCorrect = willAutoCorrect; @@ -75,7 +90,7 @@ public final class SuggestedWords { mIsObsoleteSuggestions = isObsoleteSuggestions; mIsPrediction = isPrediction; mSequenceNumber = sequenceNumber; - mTypedWord = suggestedWordInfoList.isEmpty() ? null : getWord(INDEX_OF_TYPED_WORD); + mTypedWord = typedWord; } public boolean isEmpty() { @@ -279,17 +294,21 @@ public final class SuggestedWords { // words from the member ArrayList as some other parties may expect the object to never change. public SuggestedWords getSuggestedWordsExcludingTypedWord() { final ArrayList newSuggestions = CollectionUtils.newArrayList(); + String typedWord = null; for (int i = 0; i < mSuggestedWordInfoList.size(); ++i) { final SuggestedWordInfo info = mSuggestedWordInfoList.get(i); if (SuggestedWordInfo.KIND_TYPED != info.mKind) { newSuggestions.add(info); + } else { + assert(null == typedWord); + typedWord = info.mWord; } } // We should never autocorrect, so we say the typed word is valid. Also, in this case, // no auto-correction should take place hence willAutoCorrect = false. - return new SuggestedWords(newSuggestions, true /* typedWordValid */, + return new SuggestedWords(newSuggestions, typedWord, true /* typedWordValid */, false /* willAutoCorrect */, mIsPunctuationSuggestions, mIsObsoleteSuggestions, - mIsPrediction); + mIsPrediction, NOT_A_SEQUENCE_NUMBER); } // Creates a new SuggestedWordInfo from the currently suggested words that removes all but the diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index ce3ef5374..c02f7318a 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -1225,11 +1225,10 @@ public final class InputLogic { } else { // We found suggestion spans in the word. We'll create the SuggestedWords out of // them, and make willAutoCorrect false. - final SuggestedWords suggestedWords = new SuggestedWords(suggestions, + final SuggestedWords suggestedWords = new SuggestedWords(suggestions, typedWord, true /* typedWordValid */, false /* willAutoCorrect */, false /* isPunctuationSuggestions */, false /* isObsoleteSuggestions */, - false /* isPrediction */); - // We need to pass typedWord because mWordComposer.mTypedWord may differ from typedWord. + false /* isPrediction */, SuggestedWords.NOT_A_SEQUENCE_NUMBER); mLatinIME.unsetIsAutoCorrectionIndicatorOnAndCallShowSuggestionStrip(suggestedWords, typedWord); }