Activate the code to cancel a manual pick (A5)

This finally makes active the behavior described in
Bug: 5968922

Change-Id: I363ed23270c3dea75411ea806011225097b5d07c
This commit is contained in:
Jean Chalard 2012-02-22 00:05:19 -08:00
parent 32f0af1fc4
commit 9271b770e8
3 changed files with 8 additions and 19 deletions

View file

@ -73,8 +73,7 @@ public class LastComposedWord {
} }
public boolean canCancelAutoCorrect() { public boolean canCancelAutoCorrect() {
return mActive && !TextUtils.isEmpty(mCommittedWord) return mActive && !TextUtils.isEmpty(mCommittedWord);
&& !TextUtils.equals(mTypedWord, mCommittedWord);
} }
public boolean didCommitTypedWord() { public boolean didCommitTypedWord() {

View file

@ -1466,11 +1466,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (mSuggestionsView != null && mSuggestionsView.dismissAddToDictionaryHint()) { if (mSuggestionsView != null && mSuggestionsView.dismissAddToDictionaryHint()) {
// Go back to the suggestion mode if the user canceled the // Go back to the suggestion mode if the user canceled the
// "Touch again to save". // "Touch again to save".
// NOTE: In general, we don't revert the word when backspacing // TODO: this code path is not used any more. Verify & delete.
// from a manual suggestion pick. We deliberately chose a
// different behavior only in the case of picking the first
// suggestion (typed word). It's intentional to have made this
// inconsistent with backspacing after selecting other suggestions.
restartSuggestionsOnManuallyPickedTypedWord(ic); restartSuggestionsOnManuallyPickedTypedWord(ic);
} else { } else {
// Here we must check whether there is a selection. If so we should remove the // Here we must check whether there is a selection. If so we should remove the
@ -2202,6 +2198,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
} }
// "ic" must not be null // "ic" must not be null
// TODO: rename this method to cancelCommit.
private void cancelAutoCorrect(final InputConnection ic) { private void cancelAutoCorrect(final InputConnection ic) {
final String originallyTypedWord = mLastComposedWord.mTypedWord; final String originallyTypedWord = mLastComposedWord.mTypedWord;
final CharSequence committedWord = mLastComposedWord.mCommittedWord; final CharSequence committedWord = mLastComposedWord.mCommittedWord;

View file

@ -310,17 +310,9 @@ public class WordComposer {
// `type' should be one of the LastComposedWord.COMMIT_TYPE_* constants above. // `type' should be one of the LastComposedWord.COMMIT_TYPE_* constants above.
public LastComposedWord commitWord(final int type, final String committedWord, public LastComposedWord commitWord(final int type, final String committedWord,
final int separatorCode) { final int separatorCode) {
// Note: currently, we come here whenever we commit a word. If it's any *other* kind than // Note: currently, we come here whenever we commit a word. If it's a MANUAL_PICK
// DECIDED_WORD, we should deactivate the last composed word so that we don't attempt to // or a DECIDED_WORD we may cancel the commit later; otherwise, we should deactivate
// cancel later. // the last composed word to ensure this does not happen.
// If it's a DECIDED_WORD, it may be an actual auto-correction by the IME, or what the user
// typed because the IME decided *not* to auto-correct for whatever reason.
// Ideally we would also null it when it was a DECIDED_WORD that was not an auto-correct.
// As it happens these two cases should behave differently, because the former can be
// canceled while the latter can't. Currently, we figure this out in
// LastComposedWord#didAutoCorrectToAnotherWord with #equals(). It would be marginally
// cleaner to do it here, but it would be slower (since we would #equals() for each commit,
// instead of only on cancel), and ultimately we want to figure it out even earlier anyway.
final ArrayList<int[]> codes = mCodes; final ArrayList<int[]> codes = mCodes;
final int[] xCoordinates = mXCoordinates; final int[] xCoordinates = mXCoordinates;
final int[] yCoordinates = mYCoordinates; final int[] yCoordinates = mYCoordinates;
@ -329,7 +321,8 @@ public class WordComposer {
mYCoordinates = new int[N]; mYCoordinates = new int[N];
final LastComposedWord lastComposedWord = new LastComposedWord(codes, final LastComposedWord lastComposedWord = new LastComposedWord(codes,
xCoordinates, yCoordinates, mTypedWord.toString(), committedWord, separatorCode); xCoordinates, yCoordinates, mTypedWord.toString(), committedWord, separatorCode);
if (type != LastComposedWord.COMMIT_TYPE_DECIDED_WORD) { if (type != LastComposedWord.COMMIT_TYPE_DECIDED_WORD
&& type != LastComposedWord.COMMIT_TYPE_MANUAL_PICK) {
lastComposedWord.deactivate(); lastComposedWord.deactivate();
} }
mTypedWord.setLength(0); mTypedWord.setLength(0);