aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/LatinIME.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinIME.java')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java41
1 files changed, 23 insertions, 18 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 83658f77e..d7d27b5e3 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1027,16 +1027,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (!mWordComposer.isComposingWord()) return;
final CharSequence typedWord = mWordComposer.getTypedWord();
if (typedWord.length() > 0) {
- mLastComposedWord = mWordComposer.commitWord(
- LastComposedWord.COMMIT_TYPE_USER_TYPED_WORD, typedWord.toString(),
- separatorCode);
if (ic != null) {
ic.commitText(typedWord, 1);
if (ProductionFlag.IS_EXPERIMENTAL) {
ResearchLogger.latinIME_commitText(typedWord);
}
}
- addToUserHistoryDictionary(typedWord);
+ final CharSequence prevWord = addToUserHistoryDictionary(typedWord);
+ mLastComposedWord = mWordComposer.commitWord(
+ LastComposedWord.COMMIT_TYPE_USER_TYPED_WORD, typedWord.toString(),
+ separatorCode, prevWord);
}
updateSuggestions();
}
@@ -1836,8 +1836,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mExpectingUpdateSelection = true;
commitChosenWord(autoCorrection, LastComposedWord.COMMIT_TYPE_DECIDED_WORD,
separatorCodePoint);
- // Add the word to the user history dictionary
- addToUserHistoryDictionary(autoCorrection);
if (!typedWord.equals(autoCorrection) && null != ic) {
// This will make the correction flash for a short while as a visual clue
// to the user that auto-correction happened.
@@ -1915,8 +1913,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
LastComposedWord.NOT_A_SEPARATOR);
// Don't allow cancellation of manual pick
mLastComposedWord.deactivate();
- // Add the word to the user history dictionary
- addToUserHistoryDictionary(suggestion);
mSpaceState = SPACE_STATE_PHANTOM;
// TODO: is this necessary?
mKeyboardSwitcher.updateShiftState();
@@ -1959,31 +1955,33 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
/**
* Commits the chosen word to the text field and saves it for later retrieval.
*/
- private void commitChosenWord(final CharSequence bestWord, final int commitType,
+ private void commitChosenWord(final CharSequence chosenWord, final int commitType,
final int separatorCode) {
final InputConnection ic = getCurrentInputConnection();
if (ic != null) {
if (mSettingsValues.mEnableSuggestionSpanInsertion) {
final SuggestedWords suggestedWords = mSuggestionsView.getSuggestions();
ic.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan(
- this, bestWord, suggestedWords, mIsMainDictionaryAvailable),
+ this, chosenWord, suggestedWords, mIsMainDictionaryAvailable),
1);
if (ProductionFlag.IS_EXPERIMENTAL) {
- ResearchLogger.latinIME_commitText(bestWord);
+ ResearchLogger.latinIME_commitText(chosenWord);
}
} else {
- ic.commitText(bestWord, 1);
+ ic.commitText(chosenWord, 1);
if (ProductionFlag.IS_EXPERIMENTAL) {
- ResearchLogger.latinIME_commitText(bestWord);
+ ResearchLogger.latinIME_commitText(chosenWord);
}
}
}
+ // Add the word to the user history dictionary
+ final CharSequence prevWord = addToUserHistoryDictionary(chosenWord);
// 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
// strings.
- mLastComposedWord = mWordComposer.commitWord(commitType, bestWord.toString(),
- separatorCode);
+ mLastComposedWord = mWordComposer.commitWord(commitType, chosenWord.toString(),
+ separatorCode, prevWord);
}
public void updateBigramPredictions() {
@@ -2023,15 +2021,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
setSuggestionStripShown(isSuggestionsStripVisible());
}
- private void addToUserHistoryDictionary(final CharSequence suggestion) {
- if (TextUtils.isEmpty(suggestion)) return;
+ private CharSequence addToUserHistoryDictionary(final CharSequence suggestion) {
+ if (TextUtils.isEmpty(suggestion)) return null;
// Only auto-add to dictionary if auto-correct is ON. Otherwise we'll be
// adding words in situations where the user or application really didn't
// want corrections enabled or learned.
if (!(mCorrectionMode == Suggest.CORRECTION_FULL
|| mCorrectionMode == Suggest.CORRECTION_FULL_BIGRAM)) {
- return;
+ return null;
}
if (mUserHistoryDictionary != null) {
@@ -2051,7 +2049,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
mUserHistoryDictionary.addToUserHistory(null == prevWord ? null : prevWord.toString(),
secondWord);
+ return prevWord;
}
+ return null;
}
public boolean isCursorTouchingWord() {
@@ -2136,6 +2136,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// "ic" must not be null
private void revertCommit(final InputConnection ic) {
+ final CharSequence previousWord = mLastComposedWord.mPrevWord;
final String originallyTypedWord = mLastComposedWord.mTypedWord;
final CharSequence committedWord = mLastComposedWord.mCommittedWord;
final int cancelLength = committedWord.length();
@@ -2160,6 +2161,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (ProductionFlag.IS_EXPERIMENTAL) {
ResearchLogger.latinIME_deleteSurroundingText(deleteLength);
}
+ if (!TextUtils.isEmpty(previousWord) && !TextUtils.isEmpty(committedWord)) {
+ mUserHistoryDictionary.cancelAddingUserHistory(
+ previousWord.toString(), committedWord.toString());
+ }
if (0 == separatorLength || mLastComposedWord.didCommitTypedWord()) {
// This is the case when we cancel a manual pick.
// We should restart suggestion on the word right away.