Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 030da519 authored by Jean Chalard's avatar Jean Chalard
Browse files

[IL115] Cleanup continues

Bug: 8636060
Change-Id: I944b10ec9798eec57d986e1075ba348aa0892cae
parent e110018e
Loading
Loading
Loading
Loading
+25 −28
Original line number Diff line number Diff line
@@ -1228,10 +1228,15 @@ public final class InputLogic {
                SuggestedWords.NOT_A_SEQUENCE_NUMBER, new OnGetSuggestedWordsCallback() {
                    @Override
                    public void onGetSuggestedWords(final SuggestedWords suggestedWords) {
                        final SuggestedWords suggestedWordsWithMaybeOlderSuggestions =
                                maybeRetrieveOlderSuggestions(mWordComposer.getTypedWord(),
                                        suggestedWords, mSuggestedWords);
                        holder.set(suggestedWordsWithMaybeOlderSuggestions);
                        final String typedWord = mWordComposer.getTypedWord();
                        // Show new suggestions if we have at least one. Otherwise keep the old
                        // suggestions with the new typed word. Exception: if the length of the
                        // typed word is <= 1 (after a deletion typically) we clear old suggestions.
                        if (suggestedWords.size() > 1 || typedWord.length() <= 1) {
                            holder.set(suggestedWords);
                        } else {
                            holder.set(retrieveOlderSuggestions(typedWord, mSuggestedWords));
                        }
                    }
                }
        );
@@ -1656,23 +1661,16 @@ 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.
     * Make a {@link com.android.inputmethod.latin.SuggestedWords} object containing a typed word
     * and obsolete suggestions.
     * See {@link com.android.inputmethod.latin.SuggestedWords#getTypedWordAndPreviousSuggestions(
     *      String, com.android.inputmethod.latin.SuggestedWords)}.
     * @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.
     * @param previousSuggestedWords The previously suggested words.
     * @return Obsolete suggestions with the newly typed word.
     */
    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 {
    private SuggestedWords retrieveOlderSuggestions(final String typedWord,
            final SuggestedWords previousSuggestedWords) {
        final SuggestedWords oldSuggestedWords =
                previousSuggestedWords.isPunctuationSuggestions() ? SuggestedWords.EMPTY
                        : previousSuggestedWords;
@@ -1682,7 +1680,6 @@ public final class InputLogic {
                false /* typedWordValid */, false /* hasAutoCorrectionCandidate */,
                true /* isObsoleteSuggestions */, false /* isPrediction */);
    }
    }

    /**
     * Gets a chunk of text with or the auto-correction indicator underline span as appropriate.