Straighten out resuming suggestion on kept word (A5)

This is cleanup.
This also introduces a "deactivated" state to the last committed
word, that can be used for
Bug: 5875776

Change-Id: I1855adb8ac8123f6d2c5365b0ae899145e5c3ba1
This commit is contained in:
Jean Chalard 2012-01-26 17:16:40 +09:00
parent dd5e1d157b
commit b6b8729374
3 changed files with 20 additions and 19 deletions

View file

@ -47,6 +47,8 @@ public class LastComposedWord {
public final String mTypedWord; public final String mTypedWord;
public final String mAutoCorrection; public final String mAutoCorrection;
private boolean mActive;
public static final LastComposedWord NOT_A_COMPOSED_WORD = public static final LastComposedWord NOT_A_COMPOSED_WORD =
new LastComposedWord(COMMIT_TYPE_USER_TYPED_WORD, null, null, null, "", ""); new LastComposedWord(COMMIT_TYPE_USER_TYPED_WORD, null, null, null, "", "");
@ -58,10 +60,15 @@ public class LastComposedWord {
mYCoordinates = yCoordinates; mYCoordinates = yCoordinates;
mTypedWord = typedWord; mTypedWord = typedWord;
mAutoCorrection = autoCorrection; mAutoCorrection = autoCorrection;
mActive = true;
} }
public boolean didAutoCorrectToAnotherWord() { public void deactivate() {
return !TextUtils.isEmpty(mAutoCorrection) mActive = false;
}
public boolean canCancelAutoCorrect() {
return mActive && !TextUtils.isEmpty(mAutoCorrection)
&& !TextUtils.equals(mTypedWord, mAutoCorrection); && !TextUtils.equals(mTypedWord, mAutoCorrection);
} }
} }

View file

@ -977,8 +977,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
.setHasMinimalSuggestion(false); .setHasMinimalSuggestion(false);
// When in fullscreen mode, show completions generated by the application // When in fullscreen mode, show completions generated by the application
setSuggestions(builder.build()); setSuggestions(builder.build());
mWordComposer.deleteAutoCorrection(); // TODO: is this the right thing to do? What should we auto-correct to in
mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD; // this case? This says to keep whatever the user typed.
mWordComposer.setAutoCorrection(mWordComposer.getTypedWord());
setSuggestionStripShown(true); 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, // 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 // 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". // relying on implicit values like "whether the suggestion strip is displayed".
if (mLastComposedWord.didAutoCorrectToAnotherWord()) { if (mLastComposedWord.canCancelAutoCorrect()) {
Utils.Stats.onAutoCorrectionCancellation(); Utils.Stats.onAutoCorrectionCancellation();
cancelAutoCorrect(ic); cancelAutoCorrect(ic);
return; 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 // 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 // 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. // strings.
mLastComposedWord = mWordComposer.commitWord(commitType); mLastComposedWord = mWordComposer.commitWord(commitType);
} }
@ -2165,12 +2166,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// "ic" must not be null // "ic" must not be null
private void cancelAutoCorrect(final InputConnection ic) { private void cancelAutoCorrect(final InputConnection ic) {
mWordComposer.resumeSuggestionOnLastComposedWord(mLastComposedWord); final String originallyTypedWord = mLastComposedWord.mTypedWord;
final String originallyTypedWord = mWordComposer.getTypedWord(); final CharSequence autoCorrectedTo = mLastComposedWord.mAutoCorrection;
final CharSequence autoCorrectedTo = mWordComposer.getAutoCorrectionOrNull();
final int cancelLength = autoCorrectedTo.length(); final int cancelLength = autoCorrectedTo.length();
final CharSequence separator = ic.getTextBeforeCursor(1, 0); final CharSequence separator = ic.getTextBeforeCursor(1, 0);
if (DEBUG) { if (DEBUG) {
if (mWordComposer.isComposingWord()) {
throw new RuntimeException("cancelAutoCorrect, but we are composing a word");
}
final String wordBeforeCursor = final String wordBeforeCursor =
ic.getTextBeforeCursor(cancelLength + 1, 0).subSequence(0, cancelLength) ic.getTextBeforeCursor(cancelLength + 1, 0).subSequence(0, cancelLength)
.toString(); .toString();
@ -2189,9 +2192,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
ic.commitText(originallyTypedWord, 1); ic.commitText(originallyTypedWord, 1);
// Re-insert the separator // Re-insert the separator
ic.commitText(separator, 1); ic.commitText(separator, 1);
mWordComposer.deleteAutoCorrection(); mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD;
mLastComposedWord =
mWordComposer.commitWord(LastComposedWord.COMMIT_TYPE_CANCEL_AUTO_CORRECT);
Utils.Stats.onSeparator(separator.charAt(0), WordComposer.NOT_A_COORDINATE, Utils.Stats.onSeparator(separator.charAt(0), WordComposer.NOT_A_COORDINATE,
WordComposer.NOT_A_COORDINATE); WordComposer.NOT_A_COORDINATE);
mHandler.cancelUpdateBigramPredictions(); mHandler.cancelUpdateBigramPredictions();

View file

@ -309,13 +309,6 @@ public class WordComposer {
mCurrentWord.mAutoCorrection = correction; mCurrentWord.mAutoCorrection = correction;
} }
/**
* 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. * @return the auto-correction for this word, or null if none.
*/ */