aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2013-12-19 18:30:21 +0900
committerJean Chalard <jchalard@google.com>2013-12-19 19:30:26 +0900
commit060e292628aa8ebbdc9dc951393336f4bb39bc69 (patch)
tree65f9f659a67627eb0a9bf6f8bf7662df9a1ba5b2 /java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
parent69a57bcdcd254b8e2dfbc367ef130114634c51a5 (diff)
downloadlatinime-060e292628aa8ebbdc9dc951393336f4bb39bc69.tar.gz
latinime-060e292628aa8ebbdc9dc951393336f4bb39bc69.tar.xz
latinime-060e292628aa8ebbdc9dc951393336f4bb39bc69.zip
[IL10] Move revertCommit to InputLogic
Bug: 8636060 Change-Id: Ia5788b365f05ae880bad957cbef00ecc93abb5d1
Diffstat (limited to 'java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java')
-rw-r--r--java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java66
1 files changed, 65 insertions, 1 deletions
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index 78f8885bc..15643819d 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -511,7 +511,7 @@ public final class InputLogic {
if (settingsValues.mIsInternal) {
LatinImeLoggerUtils.onAutoCorrectionCancellation();
}
- mLatinIME.revertCommit();
+ revertCommit(settingsValues, keyboardSwitcher, handler);
return;
}
if (mEnteredText != null && mConnection.sameAsTextBeforeCursor(mEnteredText)) {
@@ -757,6 +757,70 @@ public final class InputLogic {
}
/**
+ * Reverts a previous commit with auto-correction.
+ *
+ * This is triggered upon pressing backspace just after a commit with auto-correction.
+ *
+ * @param settingsValues the current settings values.
+ */
+ private void revertCommit(final SettingsValues settingsValues,
+ // TODO: remove these arguments
+ final KeyboardSwitcher keyboardSwitcher, final LatinIME.UIHandler handler) {
+ final String previousWord = mLastComposedWord.mPrevWord;
+ final String originallyTypedWord = mLastComposedWord.mTypedWord;
+ final String committedWord = mLastComposedWord.mCommittedWord;
+ final int cancelLength = committedWord.length();
+ // We want java chars, not codepoints for the following.
+ final int separatorLength = mLastComposedWord.mSeparatorString.length();
+ // TODO: should we check our saved separator against the actual contents of the text view?
+ final int deleteLength = cancelLength + separatorLength;
+ if (LatinIME.DEBUG) {
+ if (mWordComposer.isComposingWord()) {
+ throw new RuntimeException("revertCommit, but we are composing a word");
+ }
+ final CharSequence wordBeforeCursor =
+ mConnection.getTextBeforeCursor(deleteLength, 0).subSequence(0, cancelLength);
+ if (!TextUtils.equals(committedWord, wordBeforeCursor)) {
+ throw new RuntimeException("revertCommit check failed: we thought we were "
+ + "reverting \"" + committedWord
+ + "\", but before the cursor we found \"" + wordBeforeCursor + "\"");
+ }
+ }
+ mConnection.deleteSurroundingText(deleteLength, 0);
+ if (!TextUtils.isEmpty(previousWord) && !TextUtils.isEmpty(committedWord)) {
+ if (mSuggest != null) {
+ mSuggest.cancelAddingUserHistory(previousWord, committedWord);
+ }
+ }
+ final String stringToCommit = originallyTypedWord + mLastComposedWord.mSeparatorString;
+ if (settingsValues.mCurrentLanguageHasSpaces) {
+ // For languages with spaces, we revert to the typed string, but the cursor is still
+ // after the separator so we don't resume suggestions. If the user wants to correct
+ // the word, they have to press backspace again.
+ mConnection.commitText(stringToCommit, 1);
+ } else {
+ // For languages without spaces, we revert the typed string but the cursor is flush
+ // with the typed word, so we need to resume suggestions right away.
+ mWordComposer.setComposingWord(stringToCommit, previousWord,
+ keyboardSwitcher.getKeyboard());
+ mConnection.setComposingText(stringToCommit, 1);
+ }
+ if (settingsValues.mIsInternal) {
+ LatinImeLoggerUtils.onSeparator(mLastComposedWord.mSeparatorString,
+ Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE);
+ }
+ if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
+ ResearchLogger.latinIME_revertCommit(committedWord, originallyTypedWord,
+ mWordComposer.isBatchMode(), mLastComposedWord.mSeparatorString);
+ }
+ // Don't restart suggestion yet. We'll restart if the user deletes the
+ // separator.
+ mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD;
+ // We have a separator between the word and the cursor: we should show predictions.
+ handler.postUpdateSuggestionStrip();
+ }
+
+ /**
* Factor in auto-caps and manual caps and compute the current caps mode.
* @param keyboardSwitcher the keyboard switcher. Caps mode depends on its mode.
* @return the actual caps mode the keyboard is in right now.