diff options
author | 2013-12-19 18:18:18 +0900 | |
---|---|---|
committer | 2013-12-19 19:30:20 +0900 | |
commit | 69a57bcdcd254b8e2dfbc367ef130114634c51a5 (patch) | |
tree | 5834e00a392e4830c4e6e82c3ffe6bae8fee760e /java/src/com/android/inputmethod/latin/inputlogic | |
parent | 035e3885ac5db4944f3b244019ee73208a88fd39 (diff) | |
download | latinime-69a57bcdcd254b8e2dfbc367ef130114634c51a5.tar.gz latinime-69a57bcdcd254b8e2dfbc367ef130114634c51a5.tar.xz latinime-69a57bcdcd254b8e2dfbc367ef130114634c51a5.zip |
[IL9] Move commitCurrentAutoCorrection to InputLogic
Bug: 8636060
Change-Id: I405c4a537858a6d5ab0b29502a2792e8c3b2564e
Diffstat (limited to 'java/src/com/android/inputmethod/latin/inputlogic')
-rw-r--r-- | java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java | 46 |
1 files changed, 45 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 33ca25c00..78f8885bc 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -21,6 +21,7 @@ import android.text.TextUtils; import android.util.Log; import android.view.KeyCharacterMap; import android.view.KeyEvent; +import android.view.inputmethod.CorrectionInfo; import android.view.inputmethod.EditorInfo; import com.android.inputmethod.compat.SuggestionSpanUtils; @@ -401,7 +402,7 @@ public final class InputLogic { if (settingsValues.mCorrectionEnabled) { final String separator = shouldAvoidSendingCode ? LastComposedWord.NOT_A_SEPARATOR : StringUtils.newSingleCodePointString(codePoint); - mLatinIME.commitCurrentAutoCorrection(separator); + commitCurrentAutoCorrection(settingsValues, separator, handler); didAutoCorrect = true; } else { commitTyped(StringUtils.newSingleCodePointString(codePoint)); @@ -904,4 +905,47 @@ public final class InputLogic { separatorString); } } + + // TODO: Make this private + public void commitCurrentAutoCorrection(final SettingsValues settingsValues, + final String separator, + // TODO: Remove this argument. + final LatinIME.UIHandler handler) { + // Complete any pending suggestions query first + if (handler.hasPendingUpdateSuggestions()) { + mLatinIME.updateSuggestionStrip(); + } + final String typedAutoCorrection = mWordComposer.getAutoCorrectionOrNull(); + final String typedWord = mWordComposer.getTypedWord(); + final String autoCorrection = (typedAutoCorrection != null) + ? typedAutoCorrection : typedWord; + if (autoCorrection != null) { + if (TextUtils.isEmpty(typedWord)) { + throw new RuntimeException("We have an auto-correction but the typed word " + + "is empty? Impossible! I must commit suicide."); + } + if (settingsValues.mIsInternal) { + LatinImeLoggerUtils.onAutoCorrection( + typedWord, autoCorrection, separator, mWordComposer); + } + if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { + final SuggestedWords suggestedWords = mSuggestedWords; + ResearchLogger.latinIme_commitCurrentAutoCorrection(typedWord, autoCorrection, + separator, mWordComposer.isBatchMode(), suggestedWords); + } + mLatinIME.commitChosenWord(autoCorrection, LastComposedWord.COMMIT_TYPE_DECIDED_WORD, + separator); + if (!typedWord.equals(autoCorrection)) { + // This will make the correction flash for a short while as a visual clue + // to the user that auto-correction happened. It has no other effect; in particular + // note that this won't affect the text inside the text field AT ALL: it only makes + // the segment of text starting at the supplied index and running for the length + // of the auto-correction flash. At this moment, the "typedWord" argument is + // ignored by TextView. + mConnection.commitCorrection( + new CorrectionInfo(mLastSelectionEnd - typedWord.length(), + typedWord, autoCorrection)); + } + } + } } |