aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/Suggest.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/Suggest.java')
-rw-r--r--java/src/com/android/inputmethod/latin/Suggest.java42
1 files changed, 15 insertions, 27 deletions
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index 9d03e8a43..e43db352d 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -123,39 +123,27 @@ public final class Suggest {
suggestionsContainer.set(i, transformedWordInfo);
}
}
- SuggestedWordInfo.removeDups(typedWord, suggestionsContainer);
+ final boolean didRemoveTypedWord =
+ SuggestedWordInfo.removeDups(typedWord, suggestionsContainer);
- // If resumed, then we don't want to upcase everything: resuming on a fully-capitalized
- // words is rarely done to switch to another fully-capitalized word, but usually to a
- // normal, non-capitalized suggestion.
- final String firstSuggestion;
+ final SuggestedWordInfo firstSuggestedWordInfo;
final String whitelistedWord;
- if (suggestionResults.isEmpty()) {
- whitelistedWord = firstSuggestion = null;
+ if (suggestionsContainer.isEmpty()) {
+ firstSuggestedWordInfo = null;
+ whitelistedWord = null;
} else {
- final SuggestedWordInfo firstSuggestedWordInfo = getTransformedSuggestedWordInfo(
- suggestionResults.first(), suggestionResults.mLocale,
- shouldMakeSuggestionsAllUpperCase, isOnlyFirstCharCapitalized,
- trailingSingleQuotesCount);
- firstSuggestion = firstSuggestedWordInfo.mWord;
+ firstSuggestedWordInfo = suggestionsContainer.get(0);
if (!firstSuggestedWordInfo.isKindOf(SuggestedWordInfo.KIND_WHITELIST)) {
whitelistedWord = null;
} else {
- whitelistedWord = firstSuggestion;
+ whitelistedWord = firstSuggestedWordInfo.mWord;
}
}
- // We allow auto-correction if we have a whitelisted word, or if the word is not a valid
- // word of more than 1 char, except if the first suggestion is the same as the typed string
- // because in this case if it's strong enough to auto-correct that will mistakenly designate
- // the second candidate for auto-correction.
- // TODO: stop relying on indices to find where is the auto-correction in the suggested
- // words, and correct this test.
- final boolean allowsToBeAutoCorrected = (null != whitelistedWord
- && !whitelistedWord.equals(typedWord))
- || (consideredWord.length() > 1 && !mDictionaryFacilitator.isValidWord(
- consideredWord, isOnlyFirstCharCapitalized)
- && !typedWord.equals(firstSuggestion));
+ // We allow auto-correction if we have a whitelisted word, or if the word had more than
+ // one char and was not suggested.
+ final boolean allowsToBeAutoCorrected = (null != whitelistedWord)
+ || (consideredWord.length() > 1 && !didRemoveTypedWord);
final boolean hasAutoCorrection;
// TODO: using isCorrectionEnabled here is not very good. It's probably useless, because
@@ -164,10 +152,10 @@ public final class Suggest {
// the current settings. It may also be useful to know, when the setting is off, whether
// the word *would* have been auto-corrected.
if (!isCorrectionEnabled || !allowsToBeAutoCorrected || isPrediction
- || suggestionResults.isEmpty() || wordComposer.hasDigits()
+ || null == firstSuggestedWordInfo || wordComposer.hasDigits()
|| wordComposer.isMostlyCaps() || wordComposer.isResumed()
|| !mDictionaryFacilitator.hasInitializedMainDictionary()
- || suggestionResults.first().isKindOf(SuggestedWordInfo.KIND_SHORTCUT)) {
+ || firstSuggestedWordInfo.isKindOf(SuggestedWordInfo.KIND_SHORTCUT)) {
// If we don't have a main dictionary, we never want to auto-correct. The reason for
// this is, the user may have a contact whose name happens to match a valid word in
// their language, and it will unexpectedly auto-correct. For example, if the user
@@ -179,7 +167,7 @@ public final class Suggest {
hasAutoCorrection = false;
} else {
hasAutoCorrection = AutoCorrectionUtils.suggestionExceedsAutoCorrectionThreshold(
- suggestionResults.first(), consideredWord, mAutoCorrectionThreshold);
+ firstSuggestedWordInfo, consideredWord, mAutoCorrectionThreshold);
}
if (!TextUtils.isEmpty(typedWord)) {