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
|
// 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.
|
// 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.
|
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 mCorrectionMode;
|
||||||
private int mCommittedLength;
|
private int mCommittedLength;
|
||||||
|
@ -180,8 +183,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
private int mLastSelectionStart;
|
private int mLastSelectionStart;
|
||||||
private int mLastSelectionEnd;
|
private int mLastSelectionEnd;
|
||||||
|
|
||||||
// Indicates whether the suggestion strip is to be on in landscape
|
// Whether we are expecting an onUpdateSelection event to fire. If it does when we don't
|
||||||
private boolean mJustAccepted;
|
// "expect" it, it means the user actually moved the cursor.
|
||||||
|
private boolean mExpectingUpdateSelection;
|
||||||
private int mDeleteCount;
|
private int mDeleteCount;
|
||||||
private long mLastKeyTime;
|
private long mLastKeyTime;
|
||||||
|
|
||||||
|
@ -534,6 +538,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
mHasUncommittedTypedChars = false;
|
mHasUncommittedTypedChars = false;
|
||||||
mDeleteCount = 0;
|
mDeleteCount = 0;
|
||||||
mJustAddedMagicSpace = false;
|
mJustAddedMagicSpace = false;
|
||||||
|
mJustReplacedDoubleSpace = false;
|
||||||
|
|
||||||
loadSettings();
|
loadSettings();
|
||||||
updateCorrectionMode();
|
updateCorrectionMode();
|
||||||
|
@ -713,14 +718,17 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
ic.finishComposingText();
|
ic.finishComposingText();
|
||||||
}
|
}
|
||||||
mVoiceProxy.setVoiceInputHighlighted(false);
|
mVoiceProxy.setVoiceInputHighlighted(false);
|
||||||
} else if (!mHasUncommittedTypedChars && !mJustAccepted) {
|
} else if (!mHasUncommittedTypedChars && !mExpectingUpdateSelection) {
|
||||||
if (TextEntryState.isAcceptedDefault() || TextEntryState.isSpaceAfterPicked()) {
|
if (TextEntryState.isAcceptedDefault() || TextEntryState.isSpaceAfterPicked()) {
|
||||||
if (TextEntryState.isAcceptedDefault())
|
if (TextEntryState.isAcceptedDefault())
|
||||||
TextEntryState.reset();
|
TextEntryState.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!mExpectingUpdateSelection) {
|
||||||
mJustAddedMagicSpace = false; // The user moved the cursor.
|
mJustAddedMagicSpace = false; // The user moved the cursor.
|
||||||
|
mJustReplacedDoubleSpace = false;
|
||||||
}
|
}
|
||||||
}
|
mExpectingUpdateSelection = false;
|
||||||
mJustAccepted = false;
|
|
||||||
mHandler.postUpdateShiftKeyState();
|
mHandler.postUpdateShiftKeyState();
|
||||||
|
|
||||||
// Make a note of the cursor position
|
// Make a note of the cursor position
|
||||||
|
@ -970,6 +978,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
ic.commitText(". ", 1);
|
ic.commitText(". ", 1);
|
||||||
ic.endBatchEdit();
|
ic.endBatchEdit();
|
||||||
mKeyboardSwitcher.updateShiftState();
|
mKeyboardSwitcher.updateShiftState();
|
||||||
|
mJustReplacedDoubleSpace = true;
|
||||||
} else {
|
} else {
|
||||||
mHandler.startDoubleSpacesTimer();
|
mHandler.startDoubleSpacesTimer();
|
||||||
}
|
}
|
||||||
|
@ -1052,10 +1061,13 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
mLastKeyTime = when;
|
mLastKeyTime = when;
|
||||||
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
||||||
final boolean distinctMultiTouch = switcher.hasDistinctMultitouch();
|
final boolean distinctMultiTouch = switcher.hasDistinctMultitouch();
|
||||||
|
final boolean lastStateOfJustReplacedDoubleSpace = mJustReplacedDoubleSpace;
|
||||||
|
mJustReplacedDoubleSpace = false;
|
||||||
switch (primaryCode) {
|
switch (primaryCode) {
|
||||||
case Keyboard.CODE_DELETE:
|
case Keyboard.CODE_DELETE:
|
||||||
handleBackspace();
|
handleBackspace(lastStateOfJustReplacedDoubleSpace);
|
||||||
mDeleteCount++;
|
mDeleteCount++;
|
||||||
|
mExpectingUpdateSelection = true;
|
||||||
LatinImeLogger.logOnDelete();
|
LatinImeLogger.logOnDelete();
|
||||||
break;
|
break;
|
||||||
case Keyboard.CODE_SHIFT:
|
case Keyboard.CODE_SHIFT:
|
||||||
|
@ -1093,6 +1105,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
break;
|
break;
|
||||||
case Keyboard.CODE_TAB:
|
case Keyboard.CODE_TAB:
|
||||||
handleTab();
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
if (mSettingsValues.isWordSeparator(primaryCode)) {
|
if (mSettingsValues.isWordSeparator(primaryCode)) {
|
||||||
|
@ -1100,6 +1120,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
} else {
|
} else {
|
||||||
handleCharacter(primaryCode, keyCodes, x, y);
|
handleCharacter(primaryCode, keyCodes, x, y);
|
||||||
}
|
}
|
||||||
|
mExpectingUpdateSelection = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
switcher.onKey(primaryCode);
|
switcher.onKey(primaryCode);
|
||||||
// Reset after any single keystroke
|
// Reset after any single keystroke
|
||||||
|
@ -1129,7 +1151,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
mKeyboardSwitcher.onCancelInput();
|
mKeyboardSwitcher.onCancelInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleBackspace() {
|
private void handleBackspace(boolean justReplacedDoubleSpace) {
|
||||||
if (mVoiceProxy.logAndRevertVoiceInput()) return;
|
if (mVoiceProxy.logAndRevertVoiceInput()) return;
|
||||||
|
|
||||||
final InputConnection ic = getCurrentInputConnection();
|
final InputConnection ic = getCurrentInputConnection();
|
||||||
|
@ -1170,6 +1192,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
ic.endBatchEdit();
|
ic.endBatchEdit();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (justReplacedDoubleSpace) {
|
||||||
|
if (revertDoubleSpace()) {
|
||||||
|
ic.endBatchEdit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (mEnteredText != null && sameAsTextBeforeCursor(ic, mEnteredText)) {
|
if (mEnteredText != null && sameAsTextBeforeCursor(ic, mEnteredText)) {
|
||||||
ic.deleteSurroundingText(mEnteredText.length(), 0);
|
ic.deleteSurroundingText(mEnteredText.length(), 0);
|
||||||
|
@ -1515,7 +1543,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
}
|
}
|
||||||
if (mBestWord != null && mBestWord.length() > 0) {
|
if (mBestWord != null && mBestWord.length() > 0) {
|
||||||
TextEntryState.acceptedDefault(mWord.getTypedWord(), mBestWord, separatorCode);
|
TextEntryState.acceptedDefault(mWord.getTypedWord(), mBestWord, separatorCode);
|
||||||
mJustAccepted = true;
|
mExpectingUpdateSelection = true;
|
||||||
commitBestWord(mBestWord);
|
commitBestWord(mBestWord);
|
||||||
// Add the word to the auto dictionary if it's not a known word
|
// Add the word to the auto dictionary if it's not a known word
|
||||||
addToAutoAndUserBigramDictionaries(mBestWord, AutoDictionary.FREQUENCY_FOR_TYPED);
|
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.
|
// context - no user input. We should reset the word composer.
|
||||||
mWord.reset();
|
mWord.reset();
|
||||||
}
|
}
|
||||||
mJustAccepted = true;
|
mExpectingUpdateSelection = true;
|
||||||
commitBestWord(suggestion);
|
commitBestWord(suggestion);
|
||||||
// Add the word to the auto dictionary if it's not a known word
|
// Add the word to the auto dictionary if it's not a known word
|
||||||
if (index == 0) {
|
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) {
|
public boolean isWordSeparator(int code) {
|
||||||
return mSettingsValues.isWordSeparator(code);
|
return mSettingsValues.isWordSeparator(code);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue