aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod')
-rw-r--r--java/src/com/android/inputmethod/latin/LastComposedWord.java11
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java21
-rw-r--r--java/src/com/android/inputmethod/latin/WordComposer.java7
3 files changed, 20 insertions, 19 deletions
diff --git a/java/src/com/android/inputmethod/latin/LastComposedWord.java b/java/src/com/android/inputmethod/latin/LastComposedWord.java
index accc6307a..767c3a7da 100644
--- a/java/src/com/android/inputmethod/latin/LastComposedWord.java
+++ b/java/src/com/android/inputmethod/latin/LastComposedWord.java
@@ -47,6 +47,8 @@ public class LastComposedWord {
public final String mTypedWord;
public final String mAutoCorrection;
+ private boolean mActive;
+
public static final LastComposedWord NOT_A_COMPOSED_WORD =
new LastComposedWord(COMMIT_TYPE_USER_TYPED_WORD, null, null, null, "", "");
@@ -58,10 +60,15 @@ public class LastComposedWord {
mYCoordinates = yCoordinates;
mTypedWord = typedWord;
mAutoCorrection = autoCorrection;
+ mActive = true;
+ }
+
+ public void deactivate() {
+ mActive = false;
}
- public boolean didAutoCorrectToAnotherWord() {
- return !TextUtils.isEmpty(mAutoCorrection)
+ public boolean canCancelAutoCorrect() {
+ return mActive && !TextUtils.isEmpty(mAutoCorrection)
&& !TextUtils.equals(mTypedWord, mAutoCorrection);
}
}
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 62b287e3c..94da0cfb2 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -977,8 +977,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
.setHasMinimalSuggestion(false);
// When in fullscreen mode, show completions generated by the application
setSuggestions(builder.build());
- mWordComposer.deleteAutoCorrection();
- mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD;
+ // TODO: is this the right thing to do? What should we auto-correct to in
+ // this case? This says to keep whatever the user typed.
+ mWordComposer.setAutoCorrection(mWordComposer.getTypedWord());
setSuggestionStripShown(true);
}
}
@@ -1393,7 +1394,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// resuming here. The behavior needs to be different according to text field types,
// and it would be much clearer to test for them explicitly here rather than
// relying on implicit values like "whether the suggestion strip is displayed".
- if (mLastComposedWord.didAutoCorrectToAnotherWord()) {
+ if (mLastComposedWord.canCancelAutoCorrect()) {
Utils.Stats.onAutoCorrectionCancellation();
cancelAutoCorrect(ic);
return;
@@ -1999,7 +2000,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
// 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
- // WordComposer#didAutoCorrectToAnotherWord by string equality of the remembered
+ // LastComposedWord#canCancelAutoCorrect by string equality of the remembered
// strings.
mLastComposedWord = mWordComposer.commitWord(commitType);
}
@@ -2165,12 +2166,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// "ic" must not be null
private void cancelAutoCorrect(final InputConnection ic) {
- mWordComposer.resumeSuggestionOnLastComposedWord(mLastComposedWord);
- final String originallyTypedWord = mWordComposer.getTypedWord();
- final CharSequence autoCorrectedTo = mWordComposer.getAutoCorrectionOrNull();
+ final String originallyTypedWord = mLastComposedWord.mTypedWord;
+ final CharSequence autoCorrectedTo = mLastComposedWord.mAutoCorrection;
final int cancelLength = autoCorrectedTo.length();
final CharSequence separator = ic.getTextBeforeCursor(1, 0);
if (DEBUG) {
+ if (mWordComposer.isComposingWord()) {
+ throw new RuntimeException("cancelAutoCorrect, but we are composing a word");
+ }
final String wordBeforeCursor =
ic.getTextBeforeCursor(cancelLength + 1, 0).subSequence(0, cancelLength)
.toString();
@@ -2189,9 +2192,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
ic.commitText(originallyTypedWord, 1);
// Re-insert the separator
ic.commitText(separator, 1);
- mWordComposer.deleteAutoCorrection();
- mLastComposedWord =
- mWordComposer.commitWord(LastComposedWord.COMMIT_TYPE_CANCEL_AUTO_CORRECT);
+ mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD;
Utils.Stats.onSeparator(separator.charAt(0), WordComposer.NOT_A_COORDINATE,
WordComposer.NOT_A_COORDINATE);
mHandler.cancelUpdateBigramPredictions();
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java
index f994d68e3..bf132ed8c 100644
--- a/java/src/com/android/inputmethod/latin/WordComposer.java
+++ b/java/src/com/android/inputmethod/latin/WordComposer.java
@@ -310,13 +310,6 @@ public class WordComposer {
}
/**
- * Remove any auto-correction that may have been set.
- */
- public void deleteAutoCorrection() {
- mCurrentWord.mAutoCorrection = null;
- }
-
- /**
* @return the auto-correction for this word, or null if none.
*/
public CharSequence getAutoCorrectionOrNull() {