Remove a trailing "auto space" at the end of the line when the user added a new line.
Bug: 2384116main
parent
d2fdf34df9
commit
9a503e07d5
|
@ -192,6 +192,7 @@ public class LatinIME extends InputMethodService
|
||||||
private boolean mCompletionOn;
|
private boolean mCompletionOn;
|
||||||
private boolean mHasDictionary;
|
private boolean mHasDictionary;
|
||||||
private boolean mAutoSpace;
|
private boolean mAutoSpace;
|
||||||
|
private boolean mJustAddedAutoSpace;
|
||||||
private boolean mAutoCorrectEnabled;
|
private boolean mAutoCorrectEnabled;
|
||||||
private boolean mAutoCorrectOn;
|
private boolean mAutoCorrectOn;
|
||||||
private boolean mCapsLock;
|
private boolean mCapsLock;
|
||||||
|
@ -530,6 +531,7 @@ public class LatinIME extends InputMethodService
|
||||||
mComposing.setLength(0);
|
mComposing.setLength(0);
|
||||||
mPredicting = false;
|
mPredicting = false;
|
||||||
mDeleteCount = 0;
|
mDeleteCount = 0;
|
||||||
|
mJustAddedAutoSpace = false;
|
||||||
loadSettings();
|
loadSettings();
|
||||||
|
|
||||||
setCandidatesViewShown(false);
|
setCandidatesViewShown(false);
|
||||||
|
@ -618,9 +620,15 @@ public class LatinIME extends InputMethodService
|
||||||
ic.finishComposingText();
|
ic.finishComposingText();
|
||||||
}
|
}
|
||||||
mVoiceInputHighlighted = false;
|
mVoiceInputHighlighted = false;
|
||||||
} else if (!mPredicting && !mJustAccepted
|
} else if (!mPredicting && !mJustAccepted) {
|
||||||
&& TextEntryState.getState() == TextEntryState.STATE_ACCEPTED_DEFAULT) {
|
switch (TextEntryState.getState()) {
|
||||||
|
case TextEntryState.STATE_ACCEPTED_DEFAULT:
|
||||||
TextEntryState.reset();
|
TextEntryState.reset();
|
||||||
|
// fall through
|
||||||
|
case TextEntryState.STATE_SPACE_AFTER_PICKED:
|
||||||
|
mJustAddedAutoSpace = false; // The user moved the cursor.
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mJustAccepted = false;
|
mJustAccepted = false;
|
||||||
postUpdateShiftKeyState();
|
postUpdateShiftKeyState();
|
||||||
|
@ -841,6 +849,7 @@ public class LatinIME extends InputMethodService
|
||||||
ic.commitText(lastTwo.charAt(1) + " ", 1);
|
ic.commitText(lastTwo.charAt(1) + " ", 1);
|
||||||
ic.endBatchEdit();
|
ic.endBatchEdit();
|
||||||
updateShiftKeyState(getCurrentInputEditorInfo());
|
updateShiftKeyState(getCurrentInputEditorInfo());
|
||||||
|
mJustAddedAutoSpace = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -858,6 +867,7 @@ public class LatinIME extends InputMethodService
|
||||||
ic.commitText(". ", 1);
|
ic.commitText(". ", 1);
|
||||||
ic.endBatchEdit();
|
ic.endBatchEdit();
|
||||||
updateShiftKeyState(getCurrentInputEditorInfo());
|
updateShiftKeyState(getCurrentInputEditorInfo());
|
||||||
|
mJustAddedAutoSpace = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -874,6 +884,17 @@ public class LatinIME extends InputMethodService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void removeTrailingSpace() {
|
||||||
|
final InputConnection ic = getCurrentInputConnection();
|
||||||
|
if (ic == null) return;
|
||||||
|
|
||||||
|
CharSequence lastOne = ic.getTextBeforeCursor(1, 0);
|
||||||
|
if (lastOne != null && lastOne.length() == 1
|
||||||
|
&& lastOne.charAt(0) == KEYCODE_SPACE) {
|
||||||
|
ic.deleteSurroundingText(1, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean addWordToDictionary(String word) {
|
public boolean addWordToDictionary(String word) {
|
||||||
mUserDictionary.addWord(word, 128);
|
mUserDictionary.addWord(word, 128);
|
||||||
return true;
|
return true;
|
||||||
|
@ -937,6 +958,9 @@ public class LatinIME extends InputMethodService
|
||||||
sendDownUpKeyEvents(KeyEvent.KEYCODE_TAB);
|
sendDownUpKeyEvents(KeyEvent.KEYCODE_TAB);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
if (primaryCode != KEYCODE_ENTER) {
|
||||||
|
mJustAddedAutoSpace = false;
|
||||||
|
}
|
||||||
if (isWordSeparator(primaryCode)) {
|
if (isWordSeparator(primaryCode)) {
|
||||||
handleSeparator(primaryCode);
|
handleSeparator(primaryCode);
|
||||||
} else {
|
} else {
|
||||||
|
@ -962,6 +986,7 @@ public class LatinIME extends InputMethodService
|
||||||
ic.endBatchEdit();
|
ic.endBatchEdit();
|
||||||
updateShiftKeyState(getCurrentInputEditorInfo());
|
updateShiftKeyState(getCurrentInputEditorInfo());
|
||||||
mJustRevertedSeparator = null;
|
mJustRevertedSeparator = null;
|
||||||
|
mJustAddedAutoSpace = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleBackspace() {
|
private void handleBackspace() {
|
||||||
|
@ -1077,16 +1102,25 @@ public class LatinIME extends InputMethodService
|
||||||
|| mJustRevertedSeparator.charAt(0) != primaryCode)) {
|
|| mJustRevertedSeparator.charAt(0) != primaryCode)) {
|
||||||
pickDefaultSuggestion();
|
pickDefaultSuggestion();
|
||||||
pickedDefault = true;
|
pickedDefault = true;
|
||||||
|
// Picked the suggestion by the space key. We consider this
|
||||||
|
// as "added an auto space".
|
||||||
|
if (primaryCode == KEYCODE_SPACE) {
|
||||||
|
mJustAddedAutoSpace = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
commitTyped(ic);
|
commitTyped(ic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (mJustAddedAutoSpace && primaryCode == KEYCODE_ENTER) {
|
||||||
|
removeTrailingSpace();
|
||||||
|
mJustAddedAutoSpace = false;
|
||||||
|
}
|
||||||
sendKeyChar((char)primaryCode);
|
sendKeyChar((char)primaryCode);
|
||||||
TextEntryState.typedCharacter((char) primaryCode, true);
|
TextEntryState.typedCharacter((char) primaryCode, true);
|
||||||
if (TextEntryState.getState() == TextEntryState.STATE_PUNCTUATION_AFTER_ACCEPTED
|
if (TextEntryState.getState() == TextEntryState.STATE_PUNCTUATION_AFTER_ACCEPTED
|
||||||
&& primaryCode != KEYCODE_ENTER) {
|
&& primaryCode != KEYCODE_ENTER) {
|
||||||
swapPunctuationAndSpace();
|
swapPunctuationAndSpace();
|
||||||
} else if (isPredictionOn() && primaryCode == ' ') {
|
} else if (isPredictionOn() && primaryCode == KEYCODE_SPACE) {
|
||||||
//else if (TextEntryState.STATE_SPACE_AFTER_ACCEPTED) {
|
//else if (TextEntryState.STATE_SPACE_AFTER_ACCEPTED) {
|
||||||
doubleSpace();
|
doubleSpace();
|
||||||
}
|
}
|
||||||
|
@ -1390,10 +1424,13 @@ public class LatinIME extends InputMethodService
|
||||||
public void pickSuggestionManually(int index, CharSequence suggestion) {
|
public void pickSuggestionManually(int index, CharSequence suggestion) {
|
||||||
if (mAfterVoiceInput && mShowingVoiceSuggestions) mVoiceInput.logNBestChoose(index);
|
if (mAfterVoiceInput && mShowingVoiceSuggestions) mVoiceInput.logNBestChoose(index);
|
||||||
|
|
||||||
|
InputConnection ic = getCurrentInputConnection();
|
||||||
|
if (ic != null) {
|
||||||
|
ic.beginBatchEdit();
|
||||||
|
}
|
||||||
if (mCompletionOn && mCompletions != null && index >= 0
|
if (mCompletionOn && mCompletions != null && index >= 0
|
||||||
&& index < mCompletions.length) {
|
&& index < mCompletions.length) {
|
||||||
CompletionInfo ci = mCompletions[index];
|
CompletionInfo ci = mCompletions[index];
|
||||||
InputConnection ic = getCurrentInputConnection();
|
|
||||||
if (ic != null) {
|
if (ic != null) {
|
||||||
ic.commitCompletion(ci);
|
ic.commitCompletion(ci);
|
||||||
}
|
}
|
||||||
|
@ -1402,25 +1439,36 @@ public class LatinIME extends InputMethodService
|
||||||
mCandidateView.clear();
|
mCandidateView.clear();
|
||||||
}
|
}
|
||||||
updateShiftKeyState(getCurrentInputEditorInfo());
|
updateShiftKeyState(getCurrentInputEditorInfo());
|
||||||
|
if (ic != null) {
|
||||||
|
ic.endBatchEdit();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this is a punctuation, apply it through the normal key press
|
// If this is a punctuation, apply it through the normal key press
|
||||||
if (suggestion.length() == 1 && isWordSeparator(suggestion.charAt(0))) {
|
if (suggestion.length() == 1 && isWordSeparator(suggestion.charAt(0))) {
|
||||||
onKey(suggestion.charAt(0), null);
|
onKey(suggestion.charAt(0), null);
|
||||||
|
if (ic != null) {
|
||||||
|
ic.endBatchEdit();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
mJustAccepted = true;
|
||||||
pickSuggestion(suggestion);
|
pickSuggestion(suggestion);
|
||||||
TextEntryState.acceptedSuggestion(mComposing.toString(), suggestion);
|
TextEntryState.acceptedSuggestion(mComposing.toString(), suggestion);
|
||||||
// Follow it with a space
|
// Follow it with a space
|
||||||
if (mAutoSpace) {
|
if (mAutoSpace) {
|
||||||
sendSpace();
|
sendSpace();
|
||||||
|
mJustAddedAutoSpace = true;
|
||||||
}
|
}
|
||||||
// Fool the state watcher so that a subsequent backspace will not do a revert
|
// Fool the state watcher so that a subsequent backspace will not do a revert
|
||||||
TextEntryState.typedCharacter((char) KEYCODE_SPACE, true);
|
TextEntryState.typedCharacter((char) KEYCODE_SPACE, true);
|
||||||
if (index == 0 && !mSuggest.isValidWord(suggestion)) {
|
if (index == 0 && !mSuggest.isValidWord(suggestion)) {
|
||||||
mCandidateView.showAddToDictionaryHint(suggestion);
|
mCandidateView.showAddToDictionaryHint(suggestion);
|
||||||
}
|
}
|
||||||
|
if (ic != null) {
|
||||||
|
ic.endBatchEdit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pickSuggestion(CharSequence suggestion) {
|
private void pickSuggestion(CharSequence suggestion) {
|
||||||
|
|
Loading…
Reference in New Issue