Rename cancelAutoCorrect to cancelCommit (A6)
Also remove a test in debug mode that would check for absence of a situation which is now expected. Change-Id: Ia5be350bc98a604b3bf8f6057652c5534f6a19afmain
parent
2aa16dd81f
commit
bdf89ce5fe
|
@ -72,7 +72,7 @@ public class LastComposedWord {
|
||||||
mActive = false;
|
mActive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canCancelAutoCorrect() {
|
public boolean canCancelCommit() {
|
||||||
return mActive && !TextUtils.isEmpty(mCommittedWord);
|
return mActive && !TextUtils.isEmpty(mCommittedWord);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1431,16 +1431,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
ic.deleteSurroundingText(1, 0);
|
ic.deleteSurroundingText(1, 0);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// We should be very careful about auto-correction cancellation and suggestion
|
if (mLastComposedWord.canCancelCommit()) {
|
||||||
// resuming here. The behavior needs to be different according to text field types,
|
|
||||||
// and it would be much clearer to test for them explicitly here rather than
|
|
||||||
// relying on implicit values like "whether the suggestion strip is displayed".
|
|
||||||
if (mLastComposedWord.canCancelAutoCorrect()) {
|
|
||||||
Utils.Stats.onAutoCorrectionCancellation();
|
Utils.Stats.onAutoCorrectionCancellation();
|
||||||
cancelAutoCorrect(ic);
|
cancelCommit(ic);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SPACE_STATE_DOUBLE == spaceState) {
|
if (SPACE_STATE_DOUBLE == spaceState) {
|
||||||
if (revertDoubleSpaceWhileInBatchEdit(ic)) {
|
if (revertDoubleSpaceWhileInBatchEdit(ic)) {
|
||||||
// No need to reset mSpaceState, it has already be done (that's why we
|
// No need to reset mSpaceState, it has already be done (that's why we
|
||||||
|
@ -2001,7 +1996,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
}
|
}
|
||||||
// TODO: figure out here if this is an auto-correct or if the best word is actually
|
// TODO: figure out here if this is an auto-correct or if the best word is actually
|
||||||
// what user typed. Note: currently this is done much later in
|
// what user typed. Note: currently this is done much later in
|
||||||
// LastComposedWord#canCancelAutoCorrect by string equality of the remembered
|
// LastComposedWord#didCommitTypedWord by string equality of the remembered
|
||||||
// strings.
|
// strings.
|
||||||
mLastComposedWord = mWordComposer.commitWord(commitType, bestWord.toString(),
|
mLastComposedWord = mWordComposer.commitWord(commitType, bestWord.toString(),
|
||||||
separatorCode);
|
separatorCode);
|
||||||
|
@ -2166,8 +2161,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
}
|
}
|
||||||
|
|
||||||
// "ic" must not be null
|
// "ic" must not be null
|
||||||
// TODO: rename this method to cancelCommit.
|
private void cancelCommit(final InputConnection ic) {
|
||||||
private void cancelAutoCorrect(final InputConnection ic) {
|
|
||||||
final String originallyTypedWord = mLastComposedWord.mTypedWord;
|
final String originallyTypedWord = mLastComposedWord.mTypedWord;
|
||||||
final CharSequence committedWord = mLastComposedWord.mCommittedWord;
|
final CharSequence committedWord = mLastComposedWord.mCommittedWord;
|
||||||
final int cancelLength = committedWord.length();
|
final int cancelLength = committedWord.length();
|
||||||
|
@ -2176,21 +2170,16 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
// TODO: should we check our saved separator against the actual contents of the text view?
|
// TODO: should we check our saved separator against the actual contents of the text view?
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
if (mWordComposer.isComposingWord()) {
|
if (mWordComposer.isComposingWord()) {
|
||||||
throw new RuntimeException("cancelAutoCorrect, but we are composing a word");
|
throw new RuntimeException("cancelCommit, but we are composing a word");
|
||||||
}
|
}
|
||||||
final String wordBeforeCursor =
|
final String wordBeforeCursor =
|
||||||
ic.getTextBeforeCursor(cancelLength + separatorLength, 0)
|
ic.getTextBeforeCursor(cancelLength + separatorLength, 0)
|
||||||
.subSequence(0, cancelLength).toString();
|
.subSequence(0, cancelLength).toString();
|
||||||
if (!TextUtils.equals(committedWord, wordBeforeCursor)) {
|
if (!TextUtils.equals(committedWord, wordBeforeCursor)) {
|
||||||
throw new RuntimeException("cancelAutoCorrect check failed: we thought we were "
|
throw new RuntimeException("cancelCommit check failed: we thought we were "
|
||||||
+ "reverting \"" + committedWord
|
+ "reverting \"" + committedWord
|
||||||
+ "\", but before the cursor we found \"" + wordBeforeCursor + "\"");
|
+ "\", but before the cursor we found \"" + wordBeforeCursor + "\"");
|
||||||
}
|
}
|
||||||
if (TextUtils.equals(originallyTypedWord, wordBeforeCursor)) {
|
|
||||||
throw new RuntimeException("cancelAutoCorrect check failed: we wanted to cancel "
|
|
||||||
+ "auto correction and revert to \"" + originallyTypedWord
|
|
||||||
+ "\" but we found this very string before the cursor");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ic.deleteSurroundingText(cancelLength + separatorLength, 0);
|
ic.deleteSurroundingText(cancelLength + separatorLength, 0);
|
||||||
if (0 == separatorLength || mLastComposedWord.didCommitTypedWord()) {
|
if (0 == separatorLength || mLastComposedWord.didCommitTypedWord()) {
|
||||||
|
|
Loading…
Reference in New Issue