From a2a85d45e0618dc0dd7d224d5a0e7394d9003dc5 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 13 Dec 2011 15:14:02 +0900 Subject: [PATCH 1/2] Refactoring Change-Id: I57b2232f7fde32df5f6e1925aad1df988def34f9 --- java/src/com/android/inputmethod/latin/LatinIME.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 6ea642c92..f41d24722 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1386,11 +1386,15 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private void handleBackspace(final int spaceState) { if (mVoiceProxy.logAndRevertVoiceInput()) return; - final InputConnection ic = getCurrentInputConnection(); if (ic == null) return; ic.beginBatchEdit(); + handleBackspaceWhileInBatchEdit(spaceState, ic); + ic.endBatchEdit(); + } + // "ic" may not be null. + private void handleBackspaceWhileInBatchEdit(final int spaceState, final InputConnection ic) { mVoiceProxy.handleBackspace(); if (mEnteredText != null && sameAsTextBeforeCursor(ic, mEnteredText)) { @@ -1401,7 +1405,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // If we have mEnteredText, then we know that mHasUncommittedTypedChars == false. // In addition we know that spaceState is false, and that we should not be // reverting any autocorrect at this point. So we can safely return. - ic.endBatchEdit(); return; } @@ -1435,7 +1438,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mHandler.postUpdateShiftKeyState(); // If we had uncommitted chars then we know it's not time to revert any auto-correct // and that spaceState is NONE. - ic.endBatchEdit(); return; } mHandler.postUpdateShiftKeyState(); @@ -1444,7 +1446,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar Utils.Stats.onAutoCorrectionCancellation(); cancelAutoCorrect(ic); mWordSavedForAutoCorrectCancellation = null; - ic.endBatchEdit(); return; } else { mWordSavedForAutoCorrectCancellation = null; @@ -1452,14 +1453,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (SPACE_STATE_DOUBLE == spaceState) { if (revertDoubleSpace(ic)) { - ic.endBatchEdit(); // No need to reset mSpaceState, it has already be done (that's why we // receive it as a parameter) return; } } else if (SPACE_STATE_SWAP_PUNCTUATION == spaceState) { if (revertSwapPunctuation(ic)) { - ic.endBatchEdit(); // Likewise return; } @@ -1483,7 +1482,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar restartSuggestionsOnWordBeforeCursorIfAtEndOfWord(ic); } } - ic.endBatchEdit(); } private void handleTab() { From 2245c3b5b3691928b08fd6accf8d4a21fb35e26b Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 13 Dec 2011 15:17:57 +0900 Subject: [PATCH 2/2] Refactor + small bugfix postUpdateShiftKeyState used to be called also when mEnteredText is not null => this is a bugfix. The rest does not change the logic, as posting a message can be done anywhere within the function with no impact. Change-Id: I7888797c0778702d64f96701e35b611a55a6a259 --- java/src/com/android/inputmethod/latin/LatinIME.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index f41d24722..0299df446 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1397,6 +1397,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private void handleBackspaceWhileInBatchEdit(final int spaceState, final InputConnection ic) { mVoiceProxy.handleBackspace(); + // In many cases, we may have to put the keyboard in auto-shift state again. + mHandler.postUpdateShiftKeyState(); + if (mEnteredText != null && sameAsTextBeforeCursor(ic, mEnteredText)) { // Cancel multi-character input: remove the text we just entered. // This is triggered on backspace after a key that inputs multiple characters, @@ -1433,14 +1436,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } else { ic.deleteSurroundingText(1, 0); } - // If we deleted the last remaining char of a word, we may have to put the keyboard - // in auto-shift state again. - mHandler.postUpdateShiftKeyState(); // If we had uncommitted chars then we know it's not time to revert any auto-correct // and that spaceState is NONE. return; } - mHandler.postUpdateShiftKeyState(); if (null != mWordSavedForAutoCorrectCancellation) { Utils.Stats.onAutoCorrectionCancellation();