From 9271b770e81350e232c351f76f9f7a2ec23dff5f Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Wed, 22 Feb 2012 00:05:19 -0800 Subject: [PATCH] Activate the code to cancel a manual pick (A5) This finally makes active the behavior described in Bug: 5968922 Change-Id: I363ed23270c3dea75411ea806011225097b5d07c --- .../inputmethod/latin/LastComposedWord.java | 3 +-- .../com/android/inputmethod/latin/LatinIME.java | 7 ++----- .../android/inputmethod/latin/WordComposer.java | 17 +++++------------ 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LastComposedWord.java b/java/src/com/android/inputmethod/latin/LastComposedWord.java index d32b22d4f..cc1221bcb 100644 --- a/java/src/com/android/inputmethod/latin/LastComposedWord.java +++ b/java/src/com/android/inputmethod/latin/LastComposedWord.java @@ -73,8 +73,7 @@ public class LastComposedWord { } public boolean canCancelAutoCorrect() { - return mActive && !TextUtils.isEmpty(mCommittedWord) - && !TextUtils.equals(mTypedWord, mCommittedWord); + return mActive && !TextUtils.isEmpty(mCommittedWord); } public boolean didCommitTypedWord() { diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index ad85cc077..741f7f2a1 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1466,11 +1466,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (mSuggestionsView != null && mSuggestionsView.dismissAddToDictionaryHint()) { // Go back to the suggestion mode if the user canceled the // "Touch again to save". - // NOTE: In general, we don't revert the word when backspacing - // 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. + // TODO: this code path is not used any more. Verify & delete. restartSuggestionsOnManuallyPickedTypedWord(ic); } else { // 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 + // TODO: rename this method to cancelCommit. private void cancelAutoCorrect(final InputConnection ic) { final String originallyTypedWord = mLastComposedWord.mTypedWord; final CharSequence committedWord = mLastComposedWord.mCommittedWord; diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java index 0fa28e49e..8121ada7f 100644 --- a/java/src/com/android/inputmethod/latin/WordComposer.java +++ b/java/src/com/android/inputmethod/latin/WordComposer.java @@ -310,17 +310,9 @@ public class WordComposer { // `type' should be one of the LastComposedWord.COMMIT_TYPE_* constants above. public LastComposedWord commitWord(final int type, final String committedWord, final int separatorCode) { - // Note: currently, we come here whenever we commit a word. If it's any *other* kind than - // DECIDED_WORD, we should deactivate the last composed word so that we don't attempt to - // cancel later. - // 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. + // Note: currently, we come here whenever we commit a word. If it's a MANUAL_PICK + // or a DECIDED_WORD we may cancel the commit later; otherwise, we should deactivate + // the last composed word to ensure this does not happen. final ArrayList codes = mCodes; final int[] xCoordinates = mXCoordinates; final int[] yCoordinates = mYCoordinates; @@ -329,7 +321,8 @@ public class WordComposer { mYCoordinates = new int[N]; final LastComposedWord lastComposedWord = new LastComposedWord(codes, 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(); } mTypedWord.setLength(0);