aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java67
1 files changed, 28 insertions, 39 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 6ea642c92..a67e4c938 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1386,13 +1386,20 @@ 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();
+ // 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,
@@ -1401,11 +1408,9 @@ 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;
}
- final boolean deleteChar = !mHasUncommittedTypedChars;
if (mHasUncommittedTypedChars) {
final int length = mWordComposer.size();
if (length > 0) {
@@ -1418,10 +1423,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
ic.setComposingText(textWithUnderline, 1);
if (mWordComposer.size() == 0) {
mHasUncommittedTypedChars = false;
- }
- if (1 == length) {
- // 1 == length means we are about to erase the last character of the word,
- // so we can show bigrams.
+ // Remaining size equals zero means we just erased the last character of the
+ // word, so we can show bigrams.
mHandler.postUpdateBigramPredictions();
} else {
// length > 1, so we still have letters to deduce a suggestion from.
@@ -1430,42 +1433,29 @@ 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.
- ic.endBatchEdit();
- return;
- }
- mHandler.postUpdateShiftKeyState();
-
- if (null != mWordSavedForAutoCorrectCancellation) {
- Utils.Stats.onAutoCorrectionCancellation();
- cancelAutoCorrect(ic);
- mWordSavedForAutoCorrectCancellation = null;
- ic.endBatchEdit();
- return;
} else {
- mWordSavedForAutoCorrectCancellation = null;
- }
-
- 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)
+ if (null != mWordSavedForAutoCorrectCancellation) {
+ Utils.Stats.onAutoCorrectionCancellation();
+ cancelAutoCorrect(ic);
+ mWordSavedForAutoCorrectCancellation = null;
return;
+ } else {
+ mWordSavedForAutoCorrectCancellation = null;
}
- } else if (SPACE_STATE_SWAP_PUNCTUATION == spaceState) {
- if (revertSwapPunctuation(ic)) {
- ic.endBatchEdit();
- // Likewise
- return;
+
+ if (SPACE_STATE_DOUBLE == spaceState) {
+ if (revertDoubleSpace(ic)) {
+ // 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)) {
+ // Likewise
+ return;
+ }
}
- }
- if (deleteChar) {
if (mSuggestionsView != null && mSuggestionsView.dismissAddToDictionaryHint()) {
// Go back to the suggestion mode if the user canceled the
// "Touch again to save".
@@ -1483,7 +1473,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
restartSuggestionsOnWordBeforeCursorIfAtEndOfWord(ic);
}
}
- ic.endBatchEdit();
}
private void handleTab() {