diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/inputlogic')
-rw-r--r-- | java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java | 47 |
1 files changed, 37 insertions, 10 deletions
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index f2f9f1e68..7be60fd31 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -227,17 +227,16 @@ public final class InputLogic { } } - // TODO: stop relying on mApplicationSpecifiedCompletions. The SuggestionInfo object - // should contain a reference to the CompletionInfo instead. - if (settingsValues.isApplicationSpecifiedCompletionsOn() - && mLatinIME.mApplicationSpecifiedCompletions != null - && index >= 0 && index < mLatinIME.mApplicationSpecifiedCompletions.length) { + // TODO: We should not need the following branch. We should be able to take the same + // code path as for other kinds, use commitChosenWord, and do everything normally. We will + // however need to reset the suggestion strip right away, because we know we can't take + // the risk of calling commitCompletion twice because we don't know how the app will react. + if (SuggestedWordInfo.KIND_APP_DEFINED == suggestionInfo.mKind) { mSuggestedWords = SuggestedWords.EMPTY; mSuggestionStripViewAccessor.setNeutralSuggestionStrip(); keyboardSwitcher.updateShiftState(); resetComposingState(true /* alsoResetLastComposedWord */); - final CompletionInfo completionInfo = mLatinIME.mApplicationSpecifiedCompletions[index]; - mConnection.commitCompletion(completionInfo); + mConnection.commitCompletion(suggestionInfo.mApplicationSpecifiedCompletionInfo); mConnection.endBatchEdit(); return; } @@ -1230,9 +1229,8 @@ public final class InputLogic { @Override public void onGetSuggestedWords(final SuggestedWords suggestedWords) { final SuggestedWords suggestedWordsWithMaybeOlderSuggestions = - mLatinIME.maybeRetrieveOlderSuggestions( - mWordComposer.getTypedWord(), suggestedWords, - mSuggestedWords); + maybeRetrieveOlderSuggestions(mWordComposer.getTypedWord(), + suggestedWords, mSuggestedWords); holder.set(suggestedWordsWithMaybeOlderSuggestions); } } @@ -1658,6 +1656,35 @@ public final class InputLogic { } /** + * Given a typed word and computed suggested words, return an object that may or may not + * contain older suggestions according to the contents of the current suggestions. + * @param typedWord The typed word as a string. + * @param suggestedWords The computed suggested words for this typed word. + * @param previousSuggestedWords The previous suggested words. + * @return suggestions possibly enriched with older suggestions. + */ + private SuggestedWords maybeRetrieveOlderSuggestions(final String typedWord, + final SuggestedWords suggestedWords, final SuggestedWords previousSuggestedWords) { + // TODO: consolidate this into performUpdateSuggestionStripSync? + // We update the suggestion strip only when we have some suggestions to show, i.e. when + // the suggestion count is > 1; else, we leave the old suggestions, with the typed word + // replaced with the new one. However, when the length of the typed word is 1 or 0 (after + // a deletion typically), we do want to remove the old suggestions. + if (suggestedWords.size() > 1 || typedWord.length() <= 1) { + return suggestedWords; + } else { + final SuggestedWords oldSuggestedWords = + previousSuggestedWords.isPunctuationSuggestions() ? SuggestedWords.EMPTY + : previousSuggestedWords; + final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions = + SuggestedWords.getTypedWordAndPreviousSuggestions(typedWord, oldSuggestedWords); + return new SuggestedWords(typedWordAndPreviousSuggestions, null /* rawSuggestions */, + false /* typedWordValid */, false /* hasAutoCorrectionCandidate */, + true /* isObsoleteSuggestions */, false /* isPrediction */); + } + } + + /** * Gets a chunk of text with or the auto-correction indicator underline span as appropriate. * * This method looks at the old state of the auto-correction indicator to put or not put |