From f294ed3308be4cfda89effbd64affb7f9c672545 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Thu, 26 Dec 2013 22:24:59 +0900 Subject: [PATCH] Fix a code path that looks ridiculous Bug: 12295276 Change-Id: I187016b59213d351c943c6e0b9a2ad3708499646 --- .../latin/DictionaryFacilitatorForSuggest.java | 7 +++---- .../latin/inputlogic/InputLogic.java | 17 +++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java b/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java index 3f6756e39..2ddb00315 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java +++ b/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java @@ -274,10 +274,10 @@ public class DictionaryFacilitatorForSuggest { mUserDictionary.addWordToUserDictionary(word); } - public String addToUserHistory(final WordComposer wordComposer, final String previousWord, + public void addToUserHistory(final WordComposer wordComposer, final String previousWord, final String suggestion) { if (mUserHistoryDictionary == null) { - return null; + return; } final String secondWord; if (wordComposer.wasAutoCapitalized() && !wordComposer.isMostlyCaps()) { @@ -289,12 +289,11 @@ public class DictionaryFacilitatorForSuggest { // We don't add words with 0-frequency (assuming they would be profanity etc.). final int maxFreq = getMaxFrequency(suggestion); if (maxFreq == 0) { - return null; + return; } final boolean isValid = maxFreq > 0; final int timeStamp = (int)TimeUnit.MILLISECONDS.toSeconds((System.currentTimeMillis())); mUserHistoryDictionary.addToDictionary(previousWord, secondWord, isValid, timeStamp); - return previousWord; } public void cancelAddingUserHistory(final String previousWord, final String committedWord) { diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index b417a3e37..1dff1a37a 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -974,19 +974,18 @@ public final class InputLogic { mConnection.setSelection(mLastSelectionStart, mLastSelectionEnd); } - private String performAdditionToUserHistoryDictionary(final SettingsValues settingsValues, - final String suggestion) { + private void performAdditionToUserHistoryDictionary(final SettingsValues settingsValues, + final String suggestion, final String prevWord) { // If correction is not enabled, we don't add words to the user history dictionary. // That's to avoid unintended additions in some sensitive fields, or fields that // expect to receive non-words. - if (!settingsValues.mCorrectionEnabled) return null; + if (!settingsValues.mCorrectionEnabled) return; - if (TextUtils.isEmpty(suggestion)) return null; + if (TextUtils.isEmpty(suggestion)) return; final Suggest suggest = mSuggest; - if (suggest == null) return null; + if (suggest == null) return; - final String prevWord = mConnection.getNthPreviousWord(settingsValues, 2); - return suggest.mDictionaryFacilitator.addToUserHistory(mWordComposer, prevWord, suggestion); + suggest.mDictionaryFacilitator.addToUserHistory(mWordComposer, prevWord, suggestion); } public void performUpdateSuggestionStripSync(final SettingsValues settingsValues, @@ -1605,8 +1604,10 @@ public final class InputLogic { final SuggestedWords suggestedWords = mSuggestedWords; mConnection.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan(mLatinIME, chosenWord, suggestedWords), 1); + // TODO: we pass 2 here, but would it be better to move this above and pass 1 instead? + final String prevWord = mConnection.getNthPreviousWord(settingsValues, 2); // Add the word to the user history dictionary - final String prevWord = performAdditionToUserHistoryDictionary(settingsValues, chosenWord); + performAdditionToUserHistoryDictionary(settingsValues, chosenWord, prevWord); // TODO: figure out here if this is an auto-correct or if the best word is actually // what user typed. Note: currently this is done much later in // LastComposedWord#didCommitTypedWord by string equality of the remembered