From 66bb563535dbe3672f99f75bd71763a551444867 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 21 Feb 2012 23:17:54 -0800 Subject: [PATCH] Give LastComposedWord knowledge of the separator (A2) This stores the separator that was used to commit the word in the LastComposedWord. It may be NOT_A_SEPARATOR if there was no separator (for example, the cursor moved causing a commit, or there was a manual pick). This is necessary to implement feature request #5968922. Change-Id: I5fcf19a78ec66d68d4df89418eaef13952588207 --- .../inputmethod/deprecated/VoiceProxy.java | 3 ++- .../inputmethod/latin/LastComposedWord.java | 9 +++++-- .../android/inputmethod/latin/LatinIME.java | 25 +++++++++++-------- .../com/android/inputmethod/latin/Utils.java | 6 +++-- .../inputmethod/latin/WordComposer.java | 5 ++-- 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java index f632b0e02..5c4e9af68 100644 --- a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java +++ b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java @@ -56,6 +56,7 @@ import com.android.inputmethod.deprecated.voice.VoiceInput; import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.keyboard.LatinKeyboardView; import com.android.inputmethod.latin.EditingUtils; +import com.android.inputmethod.latin.LastComposedWord; import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinIME.UIHandler; import com.android.inputmethod.latin.LatinImeLogger; @@ -553,7 +554,7 @@ public class VoiceProxy implements VoiceInput.UiListener { mHints.registerVoiceResult(bestResult); if (ic != null) ic.beginBatchEdit(); // To avoid extra updates on committing older text - mService.commitTyped(ic); + mService.commitTyped(ic, LastComposedWord.NOT_A_SEPARATOR); EditingUtils.appendText(ic, bestResult); if (ic != null) ic.endBatchEdit(); diff --git a/java/src/com/android/inputmethod/latin/LastComposedWord.java b/java/src/com/android/inputmethod/latin/LastComposedWord.java index 37be03c3e..f0b91b104 100644 --- a/java/src/com/android/inputmethod/latin/LastComposedWord.java +++ b/java/src/com/android/inputmethod/latin/LastComposedWord.java @@ -40,26 +40,31 @@ public class LastComposedWord { // an auto-correction. public static final int COMMIT_TYPE_CANCEL_AUTO_CORRECT = 3; + public static final int NOT_A_SEPARATOR = -1; + public final ArrayList mCodes; public final int[] mXCoordinates; public final int[] mYCoordinates; public final String mTypedWord; public final String mCommittedWord; + public final int mSeparatorCode; private boolean mActive; public static final LastComposedWord NOT_A_COMPOSED_WORD = - new LastComposedWord(null, null, null, "", ""); + new LastComposedWord(null, null, null, "", "", NOT_A_SEPARATOR); // 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 codes, final int[] xCoordinates, - final int[] yCoordinates, final String typedWord, final String committedWord) { + final int[] yCoordinates, final String typedWord, final String committedWord, + final int separatorCode) { mCodes = codes; mXCoordinates = xCoordinates; mYCoordinates = yCoordinates; mTypedWord = typedWord; mCommittedWord = committedWord; + mSeparatorCode = separatorCode; mActive = true; } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index a40bcdfe2..b7c8b70e1 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -658,7 +658,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mDisplayOrientation = conf.orientation; mHandler.startOrientationChanging(); final InputConnection ic = getCurrentInputConnection(); - commitTyped(ic); + commitTyped(ic, LastComposedWord.NOT_A_SEPARATOR); if (ic != null) ic.finishComposingText(); // For voice input if (isShowingOptionDialog()) mOptionsDialog.dismiss(); @@ -1126,12 +1126,13 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD; } - public void commitTyped(final InputConnection ic) { + public void commitTyped(final InputConnection ic, final int separatorCode) { if (!mWordComposer.isComposingWord()) return; final CharSequence typedWord = mWordComposer.getTypedWord(); if (typedWord.length() > 0) { mLastComposedWord = mWordComposer.commitWord( - LastComposedWord.COMMIT_TYPE_USER_TYPED_WORD, typedWord.toString()); + LastComposedWord.COMMIT_TYPE_USER_TYPED_WORD, typedWord.toString(), + separatorCode); if (ic != null) { ic.commitText(typedWord, 1); } @@ -1353,7 +1354,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar final InputConnection ic = getCurrentInputConnection(); if (ic == null) return; ic.beginBatchEdit(); - commitTyped(ic); + commitTyped(ic, LastComposedWord.NOT_A_SEPARATOR); text = specificTldProcessingOnTextInput(ic, text); if (SPACE_STATE_PHANTOM == mSpaceState) { sendKeyCodePoint(Keyboard.CODE_SPACE); @@ -1646,7 +1647,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar commitCurrentAutoCorrection(primaryCode, ic); didAutoCorrect = true; } else { - commitTyped(ic); + commitTyped(ic, primaryCode); } } @@ -1703,7 +1704,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } private void handleClose() { - commitTyped(getCurrentInputConnection()); + commitTyped(getCurrentInputConnection(), LastComposedWord.NOT_A_SEPARATOR); mVoiceProxy.handleClose(); requestHideSelf(0); LatinKeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); @@ -1914,7 +1915,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } Utils.Stats.onAutoCorrection(typedWord, autoCorrection.toString(), separatorCodePoint); mExpectingUpdateSelection = true; - commitChosenWord(autoCorrection, LastComposedWord.COMMIT_TYPE_DECIDED_WORD); + commitChosenWord(autoCorrection, LastComposedWord.COMMIT_TYPE_DECIDED_WORD, + separatorCodePoint); // Add the word to the user unigram dictionary if it's not a known word addToUserUnigramAndBigramDictionaries(autoCorrection, UserUnigramDictionary.FREQUENCY_FOR_TYPED); @@ -1969,7 +1971,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar LatinImeLogger.logOnManualSuggestion(mWordComposer.getTypedWord().toString(), suggestion.toString(), index, suggestions.mWords); mExpectingUpdateSelection = true; - commitChosenWord(suggestion, LastComposedWord.COMMIT_TYPE_MANUAL_PICK); + commitChosenWord(suggestion, LastComposedWord.COMMIT_TYPE_MANUAL_PICK, + LastComposedWord.NOT_A_SEPARATOR); // Add the word to the auto dictionary if it's not a known word if (index == 0) { addToUserUnigramAndBigramDictionaries(suggestion, @@ -2019,7 +2022,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar /** * Commits the chosen word to the text field and saves it for later retrieval. */ - private void commitChosenWord(final CharSequence bestWord, final int commitType) { + private void commitChosenWord(final CharSequence bestWord, final int commitType, + final int separatorCode) { final InputConnection ic = getCurrentInputConnection(); if (ic != null) { mVoiceProxy.rememberReplacedWord(bestWord, mSettingsValues.mWordSeparators); @@ -2035,7 +2039,8 @@ 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, bestWord.toString()); + mLastComposedWord = mWordComposer.commitWord(commitType, bestWord.toString(), + separatorCode); } private static final WordComposer sEmptyWordComposer = new WordComposer(); diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index 3975dddeb..6d63e95f6 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -264,6 +264,7 @@ public class Utils { int ret = in % BUFSIZE; return ret < 0 ? ret + BUFSIZE : ret; } + // TODO: accept code points public void push(char c, int x, int y) { if (!mEnabled) return; if (mUsabilityStudy) { @@ -777,9 +778,10 @@ public class Utils { LatinImeLogger.logOnInputChar(); } - public static void onSeparator(final char code, final int x, + public static void onSeparator(final int code, final int x, final int y) { - RingCharBuffer.getInstance().push(code, x, y); + // TODO: accept code points + RingCharBuffer.getInstance().push((char)code, x, y); LatinImeLogger.logOnInputSeparator(); } diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java index 1f9371538..0fa28e49e 100644 --- a/java/src/com/android/inputmethod/latin/WordComposer.java +++ b/java/src/com/android/inputmethod/latin/WordComposer.java @@ -308,7 +308,8 @@ public class WordComposer { } // `type' should be one of the LastComposedWord.COMMIT_TYPE_* constants above. - public LastComposedWord commitWord(final int type, final String committedWord) { + public LastComposedWord commitWord(final int type, final String committedWord, + final int separatorCode) { // Note: currently, we come here whenever we commit a word. If it's any *other* kind than // DECIDED_WORD, we should deactivate the last composed word so that we don't attempt to // cancel later. @@ -327,7 +328,7 @@ public class WordComposer { mXCoordinates = new int[N]; mYCoordinates = new int[N]; final LastComposedWord lastComposedWord = new LastComposedWord(codes, - xCoordinates, yCoordinates, mTypedWord.toString(), committedWord); + xCoordinates, yCoordinates, mTypedWord.toString(), committedWord, separatorCode); if (type != LastComposedWord.COMMIT_TYPE_DECIDED_WORD) { lastComposedWord.deactivate(); }