am b6b87293: Straighten out resuming suggestion on kept word (A5)

* commit 'b6b8729374dc68b153f00730c79828532acf1ee5':
  Straighten out resuming suggestion on kept word (A5)
main
Jean Chalard 2012-01-26 02:31:40 -08:00 committed by Android Git Automerger
commit 947bb69b9d
3 changed files with 20 additions and 19 deletions

View File

@ -47,6 +47,8 @@ public class LastComposedWord {
public final String mTypedWord;
public final String mAutoCorrection;
private boolean mActive;
public static final LastComposedWord NOT_A_COMPOSED_WORD =
new LastComposedWord(COMMIT_TYPE_USER_TYPED_WORD, null, null, null, "", "");
@ -58,10 +60,15 @@ public class LastComposedWord {
mYCoordinates = yCoordinates;
mTypedWord = typedWord;
mAutoCorrection = autoCorrection;
mActive = true;
}
public boolean didAutoCorrectToAnotherWord() {
return !TextUtils.isEmpty(mAutoCorrection)
public void deactivate() {
mActive = false;
}
public boolean canCancelAutoCorrect() {
return mActive && !TextUtils.isEmpty(mAutoCorrection)
&& !TextUtils.equals(mTypedWord, mAutoCorrection);
}
}

View File

@ -977,8 +977,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
.setHasMinimalSuggestion(false);
// When in fullscreen mode, show completions generated by the application
setSuggestions(builder.build());
mWordComposer.deleteAutoCorrection();
mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD;
// TODO: is this the right thing to do? What should we auto-correct to in
// this case? This says to keep whatever the user typed.
mWordComposer.setAutoCorrection(mWordComposer.getTypedWord());
setSuggestionStripShown(true);
}
}
@ -1393,7 +1394,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// 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.didAutoCorrectToAnotherWord()) {
if (mLastComposedWord.canCancelAutoCorrect()) {
Utils.Stats.onAutoCorrectionCancellation();
cancelAutoCorrect(ic);
return;
@ -1999,7 +2000,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
// what user typed. Note: currently this is done much later in
// WordComposer#didAutoCorrectToAnotherWord by string equality of the remembered
// LastComposedWord#canCancelAutoCorrect by string equality of the remembered
// strings.
mLastComposedWord = mWordComposer.commitWord(commitType);
}
@ -2165,12 +2166,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// "ic" must not be null
private void cancelAutoCorrect(final InputConnection ic) {
mWordComposer.resumeSuggestionOnLastComposedWord(mLastComposedWord);
final String originallyTypedWord = mWordComposer.getTypedWord();
final CharSequence autoCorrectedTo = mWordComposer.getAutoCorrectionOrNull();
final String originallyTypedWord = mLastComposedWord.mTypedWord;
final CharSequence autoCorrectedTo = mLastComposedWord.mAutoCorrection;
final int cancelLength = autoCorrectedTo.length();
final CharSequence separator = ic.getTextBeforeCursor(1, 0);
if (DEBUG) {
if (mWordComposer.isComposingWord()) {
throw new RuntimeException("cancelAutoCorrect, but we are composing a word");
}
final String wordBeforeCursor =
ic.getTextBeforeCursor(cancelLength + 1, 0).subSequence(0, cancelLength)
.toString();
@ -2189,9 +2192,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
ic.commitText(originallyTypedWord, 1);
// Re-insert the separator
ic.commitText(separator, 1);
mWordComposer.deleteAutoCorrection();
mLastComposedWord =
mWordComposer.commitWord(LastComposedWord.COMMIT_TYPE_CANCEL_AUTO_CORRECT);
mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD;
Utils.Stats.onSeparator(separator.charAt(0), WordComposer.NOT_A_COORDINATE,
WordComposer.NOT_A_COORDINATE);
mHandler.cancelUpdateBigramPredictions();

View File

@ -309,13 +309,6 @@ public class WordComposer {
mCurrentWord.mAutoCorrection = correction;
}
/**
* Remove any auto-correction that may have been set.
*/
public void deleteAutoCorrection() {
mCurrentWord.mAutoCorrection = null;
}
/**
* @return the auto-correction for this word, or null if none.
*/