am 126698fd: Add a strong space behavior.
* commit '126698fdd256a2e3734634d3b923cabd800064ba': Add a strong space behavior.main
commit
53fe5fd4d3
|
@ -157,6 +157,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
SUGGESTION_VISIBILILTY_HIDE_VALUE
|
SUGGESTION_VISIBILILTY_HIDE_VALUE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static final int SPACE_STRENGTH_NORMAL = 0;
|
||||||
|
private static final int SPACE_STRENGTH_MAGIC = 1;
|
||||||
|
private static final int SPACE_STRENGTH_STRONG = 2;
|
||||||
|
|
||||||
private Settings.Values mSettingsValues;
|
private Settings.Values mSettingsValues;
|
||||||
|
|
||||||
private View mExtractArea;
|
private View mExtractArea;
|
||||||
|
@ -192,7 +196,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
private boolean mHasUncommittedTypedChars;
|
private boolean mHasUncommittedTypedChars;
|
||||||
// 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 int mLastSpaceStrength; // This indicates whether the last space is normal/magic/strong.
|
||||||
// This indicates whether the last keypress resulted in processing of double space replacement
|
// This indicates whether the last keypress resulted in processing of double space replacement
|
||||||
// with period-space.
|
// with period-space.
|
||||||
private boolean mJustReplacedDoubleSpace;
|
private boolean mJustReplacedDoubleSpace;
|
||||||
|
@ -727,7 +731,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
mComposingStringBuilder.setLength(0);
|
mComposingStringBuilder.setLength(0);
|
||||||
mHasUncommittedTypedChars = false;
|
mHasUncommittedTypedChars = false;
|
||||||
mDeleteCount = 0;
|
mDeleteCount = 0;
|
||||||
mJustAddedMagicSpace = false;
|
mLastSpaceStrength = SPACE_STRENGTH_NORMAL;
|
||||||
mJustReplacedDoubleSpace = false;
|
mJustReplacedDoubleSpace = false;
|
||||||
|
|
||||||
loadSettings();
|
loadSettings();
|
||||||
|
@ -889,6 +893,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
|| newSelEnd != candidatesEnd) && mLastSelectionStart != newSelStart;
|
|| newSelEnd != candidatesEnd) && mLastSelectionStart != newSelStart;
|
||||||
final boolean candidatesCleared = candidatesStart == -1 && candidatesEnd == -1;
|
final boolean candidatesCleared = candidatesStart == -1 && candidatesEnd == -1;
|
||||||
if (!mExpectingUpdateSelection) {
|
if (!mExpectingUpdateSelection) {
|
||||||
|
if (isShowingPunctuationList()) {
|
||||||
|
// Test for the punctuation list because there is a race condition that
|
||||||
|
// may end up in coming here on a normal key press
|
||||||
|
mLastSpaceStrength = SPACE_STRENGTH_STRONG;
|
||||||
|
}
|
||||||
if (((mComposingStringBuilder.length() > 0 && mHasUncommittedTypedChars)
|
if (((mComposingStringBuilder.length() > 0 && mHasUncommittedTypedChars)
|
||||||
|| mVoiceProxy.isVoiceInputHighlighted())
|
|| mVoiceProxy.isVoiceInputHighlighted())
|
||||||
&& (selectionChanged || candidatesCleared)) {
|
&& (selectionChanged || candidatesCleared)) {
|
||||||
|
@ -906,7 +915,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
TextEntryState.reset();
|
TextEntryState.reset();
|
||||||
updateSuggestions();
|
updateSuggestions();
|
||||||
}
|
}
|
||||||
mJustAddedMagicSpace = false; // The user moved the cursor.
|
|
||||||
mJustReplacedDoubleSpace = false;
|
mJustReplacedDoubleSpace = false;
|
||||||
}
|
}
|
||||||
mExpectingUpdateSelection = false;
|
mExpectingUpdateSelection = false;
|
||||||
|
@ -1238,6 +1246,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
return mOptionsDialog != null && mOptionsDialog.isShowing();
|
return mOptionsDialog != null && mOptionsDialog.isShowing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onCodeInputWithSpaceStrength(final int primaryCode, final int[] keyCodes,
|
||||||
|
final int x, final int y, final int spaceStrength) {
|
||||||
|
final int lastStateOfSpaceStrength = mLastSpaceStrength;
|
||||||
|
mLastSpaceStrength = spaceStrength;
|
||||||
|
onCodeInput(primaryCode, keyCodes, x, y);
|
||||||
|
mLastSpaceStrength = lastStateOfSpaceStrength;
|
||||||
|
}
|
||||||
|
|
||||||
// Implementation of {@link KeyboardActionListener}.
|
// Implementation of {@link KeyboardActionListener}.
|
||||||
@Override
|
@Override
|
||||||
public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) {
|
public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) {
|
||||||
|
@ -1323,7 +1339,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
ic.endBatchEdit();
|
ic.endBatchEdit();
|
||||||
mKeyboardSwitcher.updateShiftState();
|
mKeyboardSwitcher.updateShiftState();
|
||||||
mKeyboardSwitcher.onKey(Keyboard.CODE_DUMMY);
|
mKeyboardSwitcher.onKey(Keyboard.CODE_DUMMY);
|
||||||
mJustAddedMagicSpace = false;
|
mLastSpaceStrength = SPACE_STRENGTH_NORMAL;
|
||||||
mEnteredText = text;
|
mEnteredText = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1371,6 +1387,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
}
|
}
|
||||||
mHandler.postUpdateShiftKeyState();
|
mHandler.postUpdateShiftKeyState();
|
||||||
|
|
||||||
|
// After backspace we want to reset the space to strong to prevent an undue swap with
|
||||||
|
// a subsequent press of a punctuation sign in the suggestion strip.
|
||||||
|
mLastSpaceStrength = SPACE_STRENGTH_STRONG;
|
||||||
TextEntryState.backspace();
|
TextEntryState.backspace();
|
||||||
if (TextEntryState.isUndoCommit()) {
|
if (TextEntryState.isUndoCommit()) {
|
||||||
revertLastWord(ic);
|
revertLastWord(ic);
|
||||||
|
@ -1434,7 +1453,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
|
|
||||||
final InputConnection ic = getCurrentInputConnection();
|
final InputConnection ic = getCurrentInputConnection();
|
||||||
if (ic != null) ic.beginBatchEdit();
|
if (ic != null) ic.beginBatchEdit();
|
||||||
if (mJustAddedMagicSpace && mSettingsValues.isMagicSpaceStripper(primaryCode)) {
|
if (SPACE_STRENGTH_MAGIC == mLastSpaceStrength
|
||||||
|
&& mSettingsValues.isMagicSpaceStripper(primaryCode)) {
|
||||||
removeTrailingSpaceWhileInBatchEdit(ic);
|
removeTrailingSpaceWhileInBatchEdit(ic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1492,10 +1512,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
} else {
|
} else {
|
||||||
sendKeyChar((char)code);
|
sendKeyChar((char)code);
|
||||||
}
|
}
|
||||||
if (mJustAddedMagicSpace && mSettingsValues.isMagicSpaceSwapper(primaryCode)) {
|
if (SPACE_STRENGTH_MAGIC == mLastSpaceStrength
|
||||||
|
&& mSettingsValues.isMagicSpaceSwapper(primaryCode)) {
|
||||||
if (null != ic) swapSwapperAndSpaceWhileInBatchEdit(ic);
|
if (null != ic) swapSwapperAndSpaceWhileInBatchEdit(ic);
|
||||||
} else {
|
} else {
|
||||||
mJustAddedMagicSpace = false;
|
mLastSpaceStrength = SPACE_STRENGTH_NORMAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
switcher.updateShiftState();
|
switcher.updateShiftState();
|
||||||
|
@ -1534,7 +1555,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mJustAddedMagicSpace) {
|
if (SPACE_STRENGTH_MAGIC == mLastSpaceStrength) {
|
||||||
if (mSettingsValues.isMagicSpaceSwapper(primaryCode)) {
|
if (mSettingsValues.isMagicSpaceSwapper(primaryCode)) {
|
||||||
sendKeyChar((char)primaryCode);
|
sendKeyChar((char)primaryCode);
|
||||||
swapSwapperAndSpaceWhileInBatchEdit(ic);
|
swapSwapperAndSpaceWhileInBatchEdit(ic);
|
||||||
|
@ -1543,7 +1564,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
removeTrailingSpaceWhileInBatchEdit(ic);
|
removeTrailingSpaceWhileInBatchEdit(ic);
|
||||||
}
|
}
|
||||||
sendKeyChar((char)primaryCode);
|
sendKeyChar((char)primaryCode);
|
||||||
mJustAddedMagicSpace = false;
|
mLastSpaceStrength = SPACE_STRENGTH_NORMAL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sendKeyChar((char)primaryCode);
|
sendKeyChar((char)primaryCode);
|
||||||
|
@ -1564,6 +1585,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Keyboard.CODE_SPACE == primaryCode) {
|
if (Keyboard.CODE_SPACE == primaryCode) {
|
||||||
|
if (isShowingPunctuationList()) {
|
||||||
|
mLastSpaceStrength = SPACE_STRENGTH_STRONG;
|
||||||
|
}
|
||||||
if (!isCursorTouchingWord()) {
|
if (!isCursorTouchingWord()) {
|
||||||
mHandler.cancelUpdateSuggestions();
|
mHandler.cancelUpdateSuggestions();
|
||||||
mHandler.postUpdateBigramPredictions();
|
mHandler.postUpdateBigramPredictions();
|
||||||
|
@ -1826,12 +1850,15 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
final CharSequence beforeText = ic != null ? ic.getTextBeforeCursor(1, 0) : "";
|
final CharSequence beforeText = ic != null ? ic.getTextBeforeCursor(1, 0) : "";
|
||||||
final int toLeft = (ic == null || TextUtils.isEmpty(beforeText))
|
final int toLeft = (ic == null || TextUtils.isEmpty(beforeText))
|
||||||
? 0 : beforeText.charAt(0);
|
? 0 : beforeText.charAt(0);
|
||||||
final boolean oldMagicSpace = mJustAddedMagicSpace;
|
final int spaceStrength;
|
||||||
if (Keyboard.CODE_SPACE == toLeft) mJustAddedMagicSpace = true;
|
if (Keyboard.CODE_SPACE == toLeft && mLastSpaceStrength != SPACE_STRENGTH_STRONG) {
|
||||||
onCodeInput(primaryCode, new int[] { primaryCode },
|
spaceStrength = SPACE_STRENGTH_MAGIC;
|
||||||
|
} else {
|
||||||
|
spaceStrength = mLastSpaceStrength;
|
||||||
|
}
|
||||||
|
onCodeInputWithSpaceStrength(primaryCode, new int[] { primaryCode },
|
||||||
KeyboardActionListener.NOT_A_TOUCH_COORDINATE,
|
KeyboardActionListener.NOT_A_TOUCH_COORDINATE,
|
||||||
KeyboardActionListener.NOT_A_TOUCH_COORDINATE);
|
KeyboardActionListener.NOT_A_TOUCH_COORDINATE, spaceStrength);
|
||||||
mJustAddedMagicSpace = oldMagicSpace;
|
|
||||||
if (ic != null) {
|
if (ic != null) {
|
||||||
ic.endBatchEdit();
|
ic.endBatchEdit();
|
||||||
}
|
}
|
||||||
|
@ -2084,7 +2111,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
|
|
||||||
private void sendMagicSpace() {
|
private void sendMagicSpace() {
|
||||||
sendKeyChar((char)Keyboard.CODE_SPACE);
|
sendKeyChar((char)Keyboard.CODE_SPACE);
|
||||||
mJustAddedMagicSpace = true;
|
mLastSpaceStrength = SPACE_STRENGTH_MAGIC;
|
||||||
mKeyboardSwitcher.updateShiftState();
|
mKeyboardSwitcher.updateShiftState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue