Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 66bb5635 authored by Jean Chalard's avatar Jean Chalard
Browse files

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
parent cf9d9262
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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();

+7 −2
Original line number Diff line number Diff line
@@ -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<int[]> 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<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;
        mXCoordinates = xCoordinates;
        mYCoordinates = yCoordinates;
        mTypedWord = typedWord;
        mCommittedWord = committedWord;
        mSeparatorCode = separatorCode;
        mActive = true;
    }

+15 −10
Original line number Diff line number Diff line
@@ -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();
+4 −2
Original line number Diff line number Diff line
@@ -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();
        }

+3 −2
Original line number Diff line number Diff line
@@ -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();
        }