Fix for 2559069 IME ".com" should be erasable with one backspace
Change-Id: Ifef97a9b66e051fef7ca8b0a92bfe21f3d1e6cf6
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index b8849ed..206091b 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -226,6 +226,9 @@
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<String, List<CharSequence>> mWordToSuggestions =
new HashMap<String, List<CharSequence>>();
@@ -452,6 +455,8 @@
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 @@
if (mKeyboardSwitcher.onKey(primaryCode)) {
changeKeyboardMode();
}
+ // Reset after any single keystroke
+ mEnteredText = null;
}
public void onText(CharSequence text) {
@@ -999,6 +1006,7 @@
updateShiftKeyState(getCurrentInputEditorInfo());
mJustRevertedSeparator = null;
mJustAddedAutoSpace = false;
+ mEnteredText = text;
}
private void handleBackspace() {
@@ -1045,6 +1053,8 @@
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 @@
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) {