From dad0e792aa064765901224af56d2a53a25bc7b7d Mon Sep 17 00:00:00 2001 From: Amith Yamasani Date: Thu, 1 Apr 2010 06:28:52 -0700 Subject: [PATCH] Fix for 2559069 IME ".com" should be erasable with one backspace Change-Id: Ifef97a9b66e051fef7ca8b0a92bfe21f3d1e6cf6 --- .../com/android/inputmethod/latin/LatinIME.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index b8849ed63..206091b9e 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -226,6 +226,9 @@ public class LatinIME extends InputMethodService private long mSwipeTriggerTimeMillis; private boolean mConfigurationChanging; + // Keeps track of most recently inserted text (multi-character key) for reverting + private CharSequence mEnteredText; + // For each word, a list of potential replacements, usually from voice. private Map> mWordToSuggestions = new HashMap>(); @@ -452,6 +455,8 @@ public class LatinIME extends InputMethodService mCompletions = null; mCapsLock = false; mEmailText = false; + mEnteredText = null; + switch (attribute.inputType & EditorInfo.TYPE_MASK_CLASS) { case EditorInfo.TYPE_CLASS_NUMBER: case EditorInfo.TYPE_CLASS_DATETIME: @@ -981,6 +986,8 @@ public class LatinIME extends InputMethodService if (mKeyboardSwitcher.onKey(primaryCode)) { changeKeyboardMode(); } + // Reset after any single keystroke + mEnteredText = null; } public void onText(CharSequence text) { @@ -999,6 +1006,7 @@ public class LatinIME extends InputMethodService updateShiftKeyState(getCurrentInputEditorInfo()); mJustRevertedSeparator = null; mJustAddedAutoSpace = false; + mEnteredText = text; } private void handleBackspace() { @@ -1045,6 +1053,8 @@ public class LatinIME extends InputMethodService if (TextEntryState.getState() == TextEntryState.STATE_UNDO_COMMIT) { revertLastWord(deleteChar); return; + } else if (mEnteredText != null && sameAsTextBeforeCursor(ic, mEnteredText)) { + ic.deleteSurroundingText(mEnteredText.length(), 0); } else if (deleteChar) { sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL); if (mDeleteCount > DELETE_ACCELERATE_AT) { @@ -1594,6 +1604,11 @@ public class LatinIME extends InputMethodService return false; } + private boolean sameAsTextBeforeCursor(InputConnection ic, CharSequence text) { + CharSequence beforeText = ic.getTextBeforeCursor(text.length(), 0); + return TextUtils.equals(text, beforeText); + } + public void revertLastWord(boolean deleteChar) { final int length = mComposing.length(); if (!mPredicting && length > 0) {