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
main
Jean Chalard 2012-02-21 23:17:54 -08:00
parent cf9d92629c
commit 66bb563535
5 changed files with 31 additions and 17 deletions

View File

@ -56,6 +56,7 @@ import com.android.inputmethod.deprecated.voice.VoiceInput;
import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.keyboard.KeyboardSwitcher;
import com.android.inputmethod.keyboard.LatinKeyboardView; import com.android.inputmethod.keyboard.LatinKeyboardView;
import com.android.inputmethod.latin.EditingUtils; import com.android.inputmethod.latin.EditingUtils;
import com.android.inputmethod.latin.LastComposedWord;
import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinIME;
import com.android.inputmethod.latin.LatinIME.UIHandler; import com.android.inputmethod.latin.LatinIME.UIHandler;
import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.LatinImeLogger;
@ -553,7 +554,7 @@ public class VoiceProxy implements VoiceInput.UiListener {
mHints.registerVoiceResult(bestResult); mHints.registerVoiceResult(bestResult);
if (ic != null) ic.beginBatchEdit(); // To avoid extra updates on committing older text 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); EditingUtils.appendText(ic, bestResult);
if (ic != null) ic.endBatchEdit(); if (ic != null) ic.endBatchEdit();

View File

@ -40,26 +40,31 @@ public class LastComposedWord {
// an auto-correction. // an auto-correction.
public static final int COMMIT_TYPE_CANCEL_AUTO_CORRECT = 3; public static final int COMMIT_TYPE_CANCEL_AUTO_CORRECT = 3;
public static final int NOT_A_SEPARATOR = -1;
public final ArrayList<int[]> mCodes; public final ArrayList<int[]> mCodes;
public final int[] mXCoordinates; public final int[] mXCoordinates;
public final int[] mYCoordinates; public final int[] mYCoordinates;
public final String mTypedWord; public final String mTypedWord;
public final String mCommittedWord; public final String mCommittedWord;
public final int mSeparatorCode;
private boolean mActive; private boolean mActive;
public static final LastComposedWord NOT_A_COMPOSED_WORD = 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 // 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. // immutable. Do not fiddle with their contents after you passed them to this constructor.
public LastComposedWord(final ArrayList<int[]> codes, final int[] xCoordinates, public LastComposedWord(final ArrayList<int[]> 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; mCodes = codes;
mXCoordinates = xCoordinates; mXCoordinates = xCoordinates;
mYCoordinates = yCoordinates; mYCoordinates = yCoordinates;
mTypedWord = typedWord; mTypedWord = typedWord;
mCommittedWord = committedWord; mCommittedWord = committedWord;
mSeparatorCode = separatorCode;
mActive = true; mActive = true;
} }

View File

@ -658,7 +658,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mDisplayOrientation = conf.orientation; mDisplayOrientation = conf.orientation;
mHandler.startOrientationChanging(); mHandler.startOrientationChanging();
final InputConnection ic = getCurrentInputConnection(); final InputConnection ic = getCurrentInputConnection();
commitTyped(ic); commitTyped(ic, LastComposedWord.NOT_A_SEPARATOR);
if (ic != null) ic.finishComposingText(); // For voice input if (ic != null) ic.finishComposingText(); // For voice input
if (isShowingOptionDialog()) if (isShowingOptionDialog())
mOptionsDialog.dismiss(); mOptionsDialog.dismiss();
@ -1126,12 +1126,13 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD; 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; if (!mWordComposer.isComposingWord()) return;
final CharSequence typedWord = mWordComposer.getTypedWord(); final CharSequence typedWord = mWordComposer.getTypedWord();
if (typedWord.length() > 0) { if (typedWord.length() > 0) {
mLastComposedWord = mWordComposer.commitWord( mLastComposedWord = mWordComposer.commitWord(
LastComposedWord.COMMIT_TYPE_USER_TYPED_WORD, typedWord.toString()); LastComposedWord.COMMIT_TYPE_USER_TYPED_WORD, typedWord.toString(),
separatorCode);
if (ic != null) { if (ic != null) {
ic.commitText(typedWord, 1); ic.commitText(typedWord, 1);
} }
@ -1353,7 +1354,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final InputConnection ic = getCurrentInputConnection(); final InputConnection ic = getCurrentInputConnection();
if (ic == null) return; if (ic == null) return;
ic.beginBatchEdit(); ic.beginBatchEdit();
commitTyped(ic); commitTyped(ic, LastComposedWord.NOT_A_SEPARATOR);
text = specificTldProcessingOnTextInput(ic, text); text = specificTldProcessingOnTextInput(ic, text);
if (SPACE_STATE_PHANTOM == mSpaceState) { if (SPACE_STATE_PHANTOM == mSpaceState) {
sendKeyCodePoint(Keyboard.CODE_SPACE); sendKeyCodePoint(Keyboard.CODE_SPACE);
@ -1646,7 +1647,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
commitCurrentAutoCorrection(primaryCode, ic); commitCurrentAutoCorrection(primaryCode, ic);
didAutoCorrect = true; didAutoCorrect = true;
} else { } else {
commitTyped(ic); commitTyped(ic, primaryCode);
} }
} }
@ -1703,7 +1704,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
} }
private void handleClose() { private void handleClose() {
commitTyped(getCurrentInputConnection()); commitTyped(getCurrentInputConnection(), LastComposedWord.NOT_A_SEPARATOR);
mVoiceProxy.handleClose(); mVoiceProxy.handleClose();
requestHideSelf(0); requestHideSelf(0);
LatinKeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); LatinKeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
@ -1914,7 +1915,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
} }
Utils.Stats.onAutoCorrection(typedWord, autoCorrection.toString(), separatorCodePoint); Utils.Stats.onAutoCorrection(typedWord, autoCorrection.toString(), separatorCodePoint);
mExpectingUpdateSelection = true; 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 // Add the word to the user unigram dictionary if it's not a known word
addToUserUnigramAndBigramDictionaries(autoCorrection, addToUserUnigramAndBigramDictionaries(autoCorrection,
UserUnigramDictionary.FREQUENCY_FOR_TYPED); UserUnigramDictionary.FREQUENCY_FOR_TYPED);
@ -1969,7 +1971,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
LatinImeLogger.logOnManualSuggestion(mWordComposer.getTypedWord().toString(), LatinImeLogger.logOnManualSuggestion(mWordComposer.getTypedWord().toString(),
suggestion.toString(), index, suggestions.mWords); suggestion.toString(), index, suggestions.mWords);
mExpectingUpdateSelection = true; 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 // Add the word to the auto dictionary if it's not a known word
if (index == 0) { if (index == 0) {
addToUserUnigramAndBigramDictionaries(suggestion, 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. * 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(); final InputConnection ic = getCurrentInputConnection();
if (ic != null) { if (ic != null) {
mVoiceProxy.rememberReplacedWord(bestWord, mSettingsValues.mWordSeparators); 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 // what user typed. Note: currently this is done much later in
// LastComposedWord#canCancelAutoCorrect by string equality of the remembered // LastComposedWord#canCancelAutoCorrect by string equality of the remembered
// strings. // strings.
mLastComposedWord = mWordComposer.commitWord(commitType, bestWord.toString()); mLastComposedWord = mWordComposer.commitWord(commitType, bestWord.toString(),
separatorCode);
} }
private static final WordComposer sEmptyWordComposer = new WordComposer(); private static final WordComposer sEmptyWordComposer = new WordComposer();

View File

@ -264,6 +264,7 @@ public class Utils {
int ret = in % BUFSIZE; int ret = in % BUFSIZE;
return ret < 0 ? ret + BUFSIZE : ret; return ret < 0 ? ret + BUFSIZE : ret;
} }
// TODO: accept code points
public void push(char c, int x, int y) { public void push(char c, int x, int y) {
if (!mEnabled) return; if (!mEnabled) return;
if (mUsabilityStudy) { if (mUsabilityStudy) {
@ -777,9 +778,10 @@ public class Utils {
LatinImeLogger.logOnInputChar(); 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) { final int y) {
RingCharBuffer.getInstance().push(code, x, y); // TODO: accept code points
RingCharBuffer.getInstance().push((char)code, x, y);
LatinImeLogger.logOnInputSeparator(); LatinImeLogger.logOnInputSeparator();
} }

View File

@ -308,7 +308,8 @@ public class WordComposer {
} }
// `type' should be one of the LastComposedWord.COMMIT_TYPE_* constants above. // `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 // 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 // DECIDED_WORD, we should deactivate the last composed word so that we don't attempt to
// cancel later. // cancel later.
@ -327,7 +328,7 @@ public class WordComposer {
mXCoordinates = new int[N]; mXCoordinates = new int[N];
mYCoordinates = new int[N]; mYCoordinates = new int[N];
final LastComposedWord lastComposedWord = new LastComposedWord(codes, final LastComposedWord lastComposedWord = new LastComposedWord(codes,
xCoordinates, yCoordinates, mTypedWord.toString(), committedWord); xCoordinates, yCoordinates, mTypedWord.toString(), committedWord, separatorCode);
if (type != LastComposedWord.COMMIT_TYPE_DECIDED_WORD) { if (type != LastComposedWord.COMMIT_TYPE_DECIDED_WORD) {
lastComposedWord.deactivate(); lastComposedWord.deactivate();
} }