Enable reverting the auto-conversion of double space.
Bug: 3376923 Change-Id: If3fcfd208ad4a2b8a1452a21b07694d8d512c6ae
This commit is contained in:
parent
0143e11f11
commit
4733609947
1 changed files with 52 additions and 9 deletions
|
@ -172,6 +172,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||
// Magic space: a space that should disappear on space/apostrophe insertion, move after the
|
||||
// punctuation on punctuation insertion, and become a real space on alpha char insertion.
|
||||
private boolean mJustAddedMagicSpace; // This indicates whether the last char is a magic space.
|
||||
// This indicates whether the last keypress resulted in processing of double space replacement
|
||||
// with period-space.
|
||||
private boolean mJustReplacedDoubleSpace;
|
||||
|
||||
private int mCorrectionMode;
|
||||
private int mCommittedLength;
|
||||
|
@ -180,8 +183,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||
private int mLastSelectionStart;
|
||||
private int mLastSelectionEnd;
|
||||
|
||||
// Indicates whether the suggestion strip is to be on in landscape
|
||||
private boolean mJustAccepted;
|
||||
// Whether we are expecting an onUpdateSelection event to fire. If it does when we don't
|
||||
// "expect" it, it means the user actually moved the cursor.
|
||||
private boolean mExpectingUpdateSelection;
|
||||
private int mDeleteCount;
|
||||
private long mLastKeyTime;
|
||||
|
||||
|
@ -534,6 +538,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||
mHasUncommittedTypedChars = false;
|
||||
mDeleteCount = 0;
|
||||
mJustAddedMagicSpace = false;
|
||||
mJustReplacedDoubleSpace = false;
|
||||
|
||||
loadSettings();
|
||||
updateCorrectionMode();
|
||||
|
@ -713,14 +718,17 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||
ic.finishComposingText();
|
||||
}
|
||||
mVoiceProxy.setVoiceInputHighlighted(false);
|
||||
} else if (!mHasUncommittedTypedChars && !mJustAccepted) {
|
||||
} else if (!mHasUncommittedTypedChars && !mExpectingUpdateSelection) {
|
||||
if (TextEntryState.isAcceptedDefault() || TextEntryState.isSpaceAfterPicked()) {
|
||||
if (TextEntryState.isAcceptedDefault())
|
||||
TextEntryState.reset();
|
||||
}
|
||||
}
|
||||
if (!mExpectingUpdateSelection) {
|
||||
mJustAddedMagicSpace = false; // The user moved the cursor.
|
||||
mJustReplacedDoubleSpace = false;
|
||||
}
|
||||
}
|
||||
mJustAccepted = false;
|
||||
mExpectingUpdateSelection = false;
|
||||
mHandler.postUpdateShiftKeyState();
|
||||
|
||||
// Make a note of the cursor position
|
||||
|
@ -970,6 +978,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||
ic.commitText(". ", 1);
|
||||
ic.endBatchEdit();
|
||||
mKeyboardSwitcher.updateShiftState();
|
||||
mJustReplacedDoubleSpace = true;
|
||||
} else {
|
||||
mHandler.startDoubleSpacesTimer();
|
||||
}
|
||||
|
@ -1052,10 +1061,13 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||
mLastKeyTime = when;
|
||||
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
||||
final boolean distinctMultiTouch = switcher.hasDistinctMultitouch();
|
||||
final boolean lastStateOfJustReplacedDoubleSpace = mJustReplacedDoubleSpace;
|
||||
mJustReplacedDoubleSpace = false;
|
||||
switch (primaryCode) {
|
||||
case Keyboard.CODE_DELETE:
|
||||
handleBackspace();
|
||||
handleBackspace(lastStateOfJustReplacedDoubleSpace);
|
||||
mDeleteCount++;
|
||||
mExpectingUpdateSelection = true;
|
||||
LatinImeLogger.logOnDelete();
|
||||
break;
|
||||
case Keyboard.CODE_SHIFT:
|
||||
|
@ -1093,6 +1105,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||
break;
|
||||
case Keyboard.CODE_TAB:
|
||||
handleTab();
|
||||
// There are two cases for tab. Either we send a "next" event, that may change the
|
||||
// focus but will never move the cursor. Or, we send a real tab keycode, which some
|
||||
// applications may accept or ignore, and we don't know whether this will move the
|
||||
// cursor or not. So actually, we don't really know.
|
||||
// So to go with the safer option, we'd rather behave as if the user moved the
|
||||
// cursor when they didn't than the opposite. We also expect that most applications
|
||||
// will actually use tab only for focus movement.
|
||||
// To sum it up: do not update mExpectingUpdateSelection here.
|
||||
break;
|
||||
default:
|
||||
if (mSettingsValues.isWordSeparator(primaryCode)) {
|
||||
|
@ -1100,6 +1120,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||
} else {
|
||||
handleCharacter(primaryCode, keyCodes, x, y);
|
||||
}
|
||||
mExpectingUpdateSelection = true;
|
||||
break;
|
||||
}
|
||||
switcher.onKey(primaryCode);
|
||||
// Reset after any single keystroke
|
||||
|
@ -1129,7 +1151,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||
mKeyboardSwitcher.onCancelInput();
|
||||
}
|
||||
|
||||
private void handleBackspace() {
|
||||
private void handleBackspace(boolean justReplacedDoubleSpace) {
|
||||
if (mVoiceProxy.logAndRevertVoiceInput()) return;
|
||||
|
||||
final InputConnection ic = getCurrentInputConnection();
|
||||
|
@ -1170,6 +1192,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||
ic.endBatchEdit();
|
||||
return;
|
||||
}
|
||||
if (justReplacedDoubleSpace) {
|
||||
if (revertDoubleSpace()) {
|
||||
ic.endBatchEdit();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (mEnteredText != null && sameAsTextBeforeCursor(ic, mEnteredText)) {
|
||||
ic.deleteSurroundingText(mEnteredText.length(), 0);
|
||||
|
@ -1515,7 +1543,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||
}
|
||||
if (mBestWord != null && mBestWord.length() > 0) {
|
||||
TextEntryState.acceptedDefault(mWord.getTypedWord(), mBestWord, separatorCode);
|
||||
mJustAccepted = true;
|
||||
mExpectingUpdateSelection = true;
|
||||
commitBestWord(mBestWord);
|
||||
// Add the word to the auto dictionary if it's not a known word
|
||||
addToAutoAndUserBigramDictionaries(mBestWord, AutoDictionary.FREQUENCY_FOR_TYPED);
|
||||
|
@ -1582,7 +1610,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||
// context - no user input. We should reset the word composer.
|
||||
mWord.reset();
|
||||
}
|
||||
mJustAccepted = true;
|
||||
mExpectingUpdateSelection = true;
|
||||
commitBestWord(suggestion);
|
||||
// Add the word to the auto dictionary if it's not a known word
|
||||
if (index == 0) {
|
||||
|
@ -1792,6 +1820,21 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||
}
|
||||
}
|
||||
|
||||
public boolean revertDoubleSpace() {
|
||||
mHandler.cancelDoubleSpacesTimer();
|
||||
final InputConnection ic = getCurrentInputConnection();
|
||||
// Here we test whether we indeed have a period and a space before us. This should not
|
||||
// be needed, but it's there just in case something went wrong.
|
||||
final CharSequence textBeforeCursor = ic.getTextBeforeCursor(2, 0);
|
||||
if (!". ".equals(textBeforeCursor))
|
||||
return false;
|
||||
ic.beginBatchEdit();
|
||||
ic.deleteSurroundingText(2, 0);
|
||||
ic.commitText(" ", 1);
|
||||
ic.endBatchEdit();
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isWordSeparator(int code) {
|
||||
return mSettingsValues.isWordSeparator(code);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue