aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java23
-rw-r--r--java/src/com/android/inputmethod/latin/Suggest.java14
-rw-r--r--java/src/com/android/inputmethod/latin/SuggestedWords.java10
3 files changed, 25 insertions, 22 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 4400c7e1d..e4961d6d9 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1823,39 +1823,22 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(mWordComposer,
prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(), mCorrectionMode);
- // Here, we want to promote a whitelisted word if exists.
- // TODO: Change this scheme - a boolean is not enough. A whitelisted word may be "valid"
- // but still autocorrected from - in the case the whitelist only capitalizes the word.
- // The whitelist should be case-insensitive, so it's not possible to be consistent with
- // a boolean flag. Right now this is handled with a slight hack in
- // WhitelistDictionary#shouldForciblyAutoCorrectFrom.
- final boolean allowsToBeAutoCorrected = AutoCorrection.allowsToBeAutoCorrected(
- mSuggest.getUnigramDictionaries(),
- // If the typed string ends with a single quote, for dictionary lookup purposes
- // we behave as if the single quote was not here. Here, we are looking up the
- // typed string in the dictionary (to avoid autocorrecting from an existing
- // word, so for consistency this lookup should be made WITHOUT the trailing
- // single quote.
- quotesCount > 0
- ? typedWord.subSequence(0, typedWord.length() - quotesCount) : typedWord,
- preferCapitalization());
-
// Basically, we update the suggestion strip only when suggestion count > 1. However,
// there is an exception: We update the suggestion strip whenever typed word's length
// is 1 or typed word is found in dictionary, regardless of suggestion count. Actually,
// in most cases, suggestion count is 1 when typed word's length is 1, but we do always
// need to clear the previous state when the user starts typing a word (i.e. typed word's
// length == 1).
- if (builder.size() > 1 || typedWord.length() == 1 || (!allowsToBeAutoCorrected)
+ if (builder.size() > 1 || typedWord.length() == 1 || !builder.allowsToBeAutoCorrected()
|| mSuggestionsView.isShowingAddToDictionaryHint()) {
boolean autoCorrectionAvailable = mSuggest.hasAutoCorrection();
if (mCorrectionMode == Suggest.CORRECTION_FULL
|| mCorrectionMode == Suggest.CORRECTION_FULL_BIGRAM) {
- autoCorrectionAvailable |= (!allowsToBeAutoCorrected);
+ autoCorrectionAvailable |= !builder.allowsToBeAutoCorrected();
}
// Don't auto-correct words with multiple capital letter
autoCorrectionAvailable &= !mWordComposer.isMostlyCaps();
- builder.setTypedWordValid(!allowsToBeAutoCorrected).setHasMinimalSuggestion(
+ builder.setTypedWordValid(!builder.allowsToBeAutoCorrected()).setHasMinimalSuggestion(
autoCorrectionAvailable);
if (Suggest.shouldBlockAutoCorrectionBySafetyNet(builder, mSuggest,
mSettingsValues.mAutoCorrectionThreshold)) {
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index b6a7ce74a..4773ac55a 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -282,6 +282,14 @@ public class Suggest implements Dictionary.WordCallback {
Dictionary.UNIGRAM);
mConsideredWord = consideredWord;
+ // TODO: Change this scheme - a boolean is not enough. A whitelisted word may be "valid"
+ // but still autocorrected from - in the case the whitelist only capitalizes the word.
+ // The whitelist should be case-insensitive, so it's not possible to be consistent with
+ // a boolean flag. Right now this is handled with a slight hack in
+ // WhitelistDictionary#shouldForciblyAutoCorrectFrom.
+ final boolean allowsToBeAutoCorrected = AutoCorrection.allowsToBeAutoCorrected(
+ getUnigramDictionaries(), consideredWord, wordComposer.isFirstCharCapitalized());
+
if (wordComposer.size() <= 1 && (correctionMode == CORRECTION_FULL_BIGRAM)) {
// At first character typed, search only the bigrams
Arrays.fill(mBigramScores, 0);
@@ -393,9 +401,11 @@ public class Suggest implements Dictionary.WordCallback {
for (int i = mScores.length; i < mSuggestions.size(); ++i) {
scoreInfoList.add(new SuggestedWords.SuggestedWordInfo("--", false));
}
- return new SuggestedWords.Builder().addWords(mSuggestions, scoreInfoList);
+ return new SuggestedWords.Builder().addWords(mSuggestions, scoreInfoList)
+ .setAllowsToBeAutoCorrected(allowsToBeAutoCorrected);
}
- return new SuggestedWords.Builder().addWords(mSuggestions, null);
+ return new SuggestedWords.Builder().addWords(mSuggestions, null)
+ .setAllowsToBeAutoCorrected(allowsToBeAutoCorrected);
}
public boolean hasAutoCorrection() {
diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java
index aad975e46..c92c72004 100644
--- a/java/src/com/android/inputmethod/latin/SuggestedWords.java
+++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java
@@ -90,6 +90,7 @@ public class SuggestedWords {
private boolean mHasMinimalSuggestion;
private boolean mIsPunctuationSuggestions;
private boolean mShouldBlockAutoCorrectionBySafetyNet;
+ private boolean mAllowsToBeAutoCorrected;
private List<SuggestedWordInfo> mSuggestedWordInfoList =
new ArrayList<SuggestedWordInfo>();
@@ -159,6 +160,11 @@ public class SuggestedWords {
return this;
}
+ public Builder setAllowsToBeAutoCorrected(final boolean allowsToBeAutoCorrected) {
+ mAllowsToBeAutoCorrected = allowsToBeAutoCorrected;
+ return this;
+ }
+
// Should get rid of the first one (what the user typed previously) from suggestions
// and replace it with what the user currently typed.
public Builder addTypedWordAndPreviousSuggestions(CharSequence typedWord,
@@ -200,6 +206,10 @@ public class SuggestedWords {
return mTypedWordValid;
}
+ public boolean allowsToBeAutoCorrected() {
+ return mAllowsToBeAutoCorrected;
+ }
+
@Override
public String toString() {
// Pretty-print method to help debug