Merge "Give LastComposedWord knowledge of the committed word (A1)"
commit
1dfdc8056c
|
@ -44,7 +44,7 @@ public class LastComposedWord {
|
|||
public final int[] mXCoordinates;
|
||||
public final int[] mYCoordinates;
|
||||
public final String mTypedWord;
|
||||
public final String mAutoCorrection;
|
||||
public final String mCommittedWord;
|
||||
|
||||
private boolean mActive;
|
||||
|
||||
|
@ -54,12 +54,12 @@ public class LastComposedWord {
|
|||
// Warning: this is using the passed objects as is and fully expects them to be
|
||||
// immutable. Do not fiddle with their contents after you passed them to this constructor.
|
||||
public LastComposedWord(final ArrayList<int[]> codes, final int[] xCoordinates,
|
||||
final int[] yCoordinates, final String typedWord, final String autoCorrection) {
|
||||
final int[] yCoordinates, final String typedWord, final String committedWord) {
|
||||
mCodes = codes;
|
||||
mXCoordinates = xCoordinates;
|
||||
mYCoordinates = yCoordinates;
|
||||
mTypedWord = typedWord;
|
||||
mAutoCorrection = autoCorrection;
|
||||
mCommittedWord = committedWord;
|
||||
mActive = true;
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ public class LastComposedWord {
|
|||
}
|
||||
|
||||
public boolean canCancelAutoCorrect() {
|
||||
return mActive && !TextUtils.isEmpty(mAutoCorrection)
|
||||
&& !TextUtils.equals(mTypedWord, mAutoCorrection);
|
||||
return mActive && !TextUtils.isEmpty(mCommittedWord)
|
||||
&& !TextUtils.equals(mTypedWord, mCommittedWord);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1129,8 +1129,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||
public void commitTyped(final InputConnection ic) {
|
||||
if (!mWordComposer.isComposingWord()) return;
|
||||
final CharSequence typedWord = mWordComposer.getTypedWord();
|
||||
mLastComposedWord = mWordComposer.commitWord(LastComposedWord.COMMIT_TYPE_USER_TYPED_WORD);
|
||||
if (typedWord.length() > 0) {
|
||||
mLastComposedWord = mWordComposer.commitWord(
|
||||
LastComposedWord.COMMIT_TYPE_USER_TYPED_WORD, typedWord.toString());
|
||||
if (ic != null) {
|
||||
ic.commitText(typedWord, 1);
|
||||
}
|
||||
|
@ -2002,7 +2003,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||
// what user typed. Note: currently this is done much later in
|
||||
// LastComposedWord#canCancelAutoCorrect by string equality of the remembered
|
||||
// strings.
|
||||
mLastComposedWord = mWordComposer.commitWord(commitType);
|
||||
mLastComposedWord = mWordComposer.commitWord(commitType, bestWord.toString());
|
||||
}
|
||||
|
||||
private static final WordComposer sEmptyWordComposer = new WordComposer();
|
||||
|
@ -2166,8 +2167,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||
// "ic" must not be null
|
||||
private void cancelAutoCorrect(final InputConnection ic) {
|
||||
final String originallyTypedWord = mLastComposedWord.mTypedWord;
|
||||
final CharSequence autoCorrectedTo = mLastComposedWord.mAutoCorrection;
|
||||
final int cancelLength = autoCorrectedTo.length();
|
||||
final CharSequence committedWord = mLastComposedWord.mCommittedWord;
|
||||
final int cancelLength = committedWord.length();
|
||||
final CharSequence separator = ic.getTextBeforeCursor(1, 0);
|
||||
if (DEBUG) {
|
||||
if (mWordComposer.isComposingWord()) {
|
||||
|
@ -2176,9 +2177,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||
final String wordBeforeCursor =
|
||||
ic.getTextBeforeCursor(cancelLength + 1, 0).subSequence(0, cancelLength)
|
||||
.toString();
|
||||
if (!TextUtils.equals(autoCorrectedTo, wordBeforeCursor)) {
|
||||
if (!TextUtils.equals(committedWord, wordBeforeCursor)) {
|
||||
throw new RuntimeException("cancelAutoCorrect check failed: we thought we were "
|
||||
+ "reverting \"" + autoCorrectedTo
|
||||
+ "reverting \"" + committedWord
|
||||
+ "\", but before the cursor we found \"" + wordBeforeCursor + "\"");
|
||||
}
|
||||
if (TextUtils.equals(originallyTypedWord, wordBeforeCursor)) {
|
||||
|
|
|
@ -308,9 +308,10 @@ public class WordComposer {
|
|||
}
|
||||
|
||||
// `type' should be one of the LastComposedWord.COMMIT_TYPE_* constants above.
|
||||
public LastComposedWord commitWord(final int type) {
|
||||
public LastComposedWord commitWord(final int type, final String committedWord) {
|
||||
// Note: currently, we come here whenever we commit a word. If it's any *other* kind than
|
||||
// DECIDED_WORD, we should reset mAutoCorrection so that we don't attempt to cancel later.
|
||||
// DECIDED_WORD, we should deactivate the last composed word so that we don't attempt to
|
||||
// cancel later.
|
||||
// If it's a DECIDED_WORD, it may be an actual auto-correction by the IME, or what the user
|
||||
// typed because the IME decided *not* to auto-correct for whatever reason.
|
||||
// Ideally we would also null it when it was a DECIDED_WORD that was not an auto-correct.
|
||||
|
@ -326,8 +327,7 @@ public class WordComposer {
|
|||
mXCoordinates = new int[N];
|
||||
mYCoordinates = new int[N];
|
||||
final LastComposedWord lastComposedWord = new LastComposedWord(codes,
|
||||
xCoordinates, yCoordinates, mTypedWord.toString(),
|
||||
null == mAutoCorrection ? null : mAutoCorrection.toString());
|
||||
xCoordinates, yCoordinates, mTypedWord.toString(), committedWord);
|
||||
if (type != LastComposedWord.COMMIT_TYPE_DECIDED_WORD) {
|
||||
lastComposedWord.deactivate();
|
||||
}
|
||||
|
@ -342,6 +342,6 @@ public class WordComposer {
|
|||
mYCoordinates = lastComposedWord.mYCoordinates;
|
||||
mTypedWord.setLength(0);
|
||||
mTypedWord.append(lastComposedWord.mTypedWord);
|
||||
mAutoCorrection = lastComposedWord.mAutoCorrection;
|
||||
mAutoCorrection = null; // This will be filled by the next call to updateSuggestion.
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue