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

Commit 3b95eaf7 authored by Kurt Partridge's avatar Kurt Partridge
Browse files

[Rlog50] capture bigrams properly even with deletions

multi-project commit with Ia4ec213e8356897807cb6a278fccdbaa945732f0

Change-Id: Ib3fe886dc889954a31586ab81d00a21d8d55efd2
parent 125ad223
Loading
Loading
Loading
Loading
+24 −11
Original line number Diff line number Diff line
@@ -1131,7 +1131,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
            commitChosenWord(typedWord, LastComposedWord.COMMIT_TYPE_USER_TYPED_WORD,
                    separatorString);
            if (ProductionFlag.IS_EXPERIMENTAL) {
                ResearchLogger.getInstance().onWordFinished(typedWord);
                ResearchLogger.getInstance().onWordFinished(typedWord, mWordComposer.isBatchMode());
            }
        }
    }
@@ -1163,7 +1163,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
    }

    private void swapSwapperAndSpace() {
        CharSequence lastTwo = mConnection.getTextBeforeCursor(2, 0);
        final CharSequence lastTwo = mConnection.getTextBeforeCursor(2, 0);
        // It is guaranteed lastTwo.charAt(1) is a swapper - else this method is not called.
        if (lastTwo != null && lastTwo.length() == 2
                && lastTwo.charAt(0) == Constants.CODE_SPACE) {
@@ -1171,7 +1171,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
            final String text = lastTwo.charAt(1) + " ";
            mConnection.commitText(text, 1);
            if (ProductionFlag.IS_EXPERIMENTAL) {
                ResearchLogger.latinIME_swapSwapperAndSpace(text);
                ResearchLogger.latinIME_swapSwapperAndSpace(lastTwo, text);
            }
            mKeyboardSwitcher.updateShiftState();
        }
@@ -1191,7 +1191,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
            final String textToInsert = ". ";
            mConnection.commitText(textToInsert, 1);
            if (ProductionFlag.IS_EXPERIMENTAL) {
                ResearchLogger.latinIME_maybeDoubleSpacePeriod(textToInsert);
                ResearchLogger.latinIME_maybeDoubleSpacePeriod(textToInsert,
                        false /* isBatchMode */);
            }
            mKeyboardSwitcher.updateShiftState();
            return true;
@@ -1440,7 +1441,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
        }
        mConnection.commitText(text, 1);
        if (ProductionFlag.IS_EXPERIMENTAL) {
            ResearchLogger.latinIME_onTextInput(text);
            ResearchLogger.latinIME_onTextInput(text, false /* isBatchMode */);
        }
        mConnection.endBatchEdit();
        // Space state must be updated before calling updateShiftState
@@ -1665,10 +1666,13 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
            final int length = mWordComposer.size();
            if (length > 0) {
                if (mWordComposer.isBatchMode()) {
                    mWordComposer.reset();
                    if (ProductionFlag.IS_EXPERIMENTAL) {
                        ResearchLogger.latinIME_handleBackspace_batch(mWordComposer.getTypedWord());
                        final String word = mWordComposer.getTypedWord();
                        ResearchLogger.latinIME_handleBackspace_batch(word);
                        ResearchLogger.getInstance().uncommitCurrentLogUnit(
                                word, false /* dumpCurrentLogUnit */);
                    }
                    mWordComposer.reset();
                } else {
                    mWordComposer.deleteLast();
                }
@@ -2084,7 +2088,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
            }
            if (ProductionFlag.IS_EXPERIMENTAL) {
                ResearchLogger.latinIme_commitCurrentAutoCorrection(typedWord, autoCorrection,
                        separatorString);
                        separatorString, mWordComposer.isBatchMode());
            }
            mExpectingUpdateSelection = true;
            commitChosenWord(autoCorrection, LastComposedWord.COMMIT_TYPE_DECIDED_WORD,
@@ -2118,7 +2122,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
            onCodeInput(primaryCode,
                    Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE);
            if (ProductionFlag.IS_EXPERIMENTAL) {
                ResearchLogger.latinIME_punctuationSuggestion(index, suggestion);
                ResearchLogger.latinIME_punctuationSuggestion(index, suggestion,
                        false /* isBatchMode */);
            }
            return;
        }
@@ -2157,7 +2162,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
        commitChosenWord(suggestion, LastComposedWord.COMMIT_TYPE_MANUAL_PICK,
                LastComposedWord.NOT_A_SEPARATOR);
        if (ProductionFlag.IS_EXPERIMENTAL) {
            ResearchLogger.latinIME_pickSuggestionManually(replacedWord, index, suggestion);
            ResearchLogger.latinIME_pickSuggestionManually(replacedWord, index, suggestion,
                    mWordComposer.isBatchMode());
        }
        mConnection.endBatchEdit();
        // Don't allow cancellation of manual pick
@@ -2254,6 +2260,12 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
                mConnection.getWordBeforeCursorIfAtEndOfWord(mSettings.getCurrent());
        if (null != word) {
            restartSuggestionsOnWordBeforeCursor(word);
            // TODO: Handle the case where the user manually moves the cursor and then backs up over
            // a separator.  In that case, the current log unit should not be uncommitted.
            if (ProductionFlag.IS_EXPERIMENTAL) {
                ResearchLogger.getInstance().uncommitCurrentLogUnit(word.toString(),
                        true /* dumpCurrentLogUnit */);
            }
        }
    }

@@ -2297,7 +2309,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
                    Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE);
        }
        if (ProductionFlag.IS_EXPERIMENTAL) {
            ResearchLogger.latinIME_revertCommit(committedWord, originallyTypedWord);
            ResearchLogger.latinIME_revertCommit(committedWord, originallyTypedWord,
                    mWordComposer.isBatchMode());
        }
        // Don't restart suggestion yet. We'll restart if the user deletes the
        // separator.
+5 −4
Original line number Diff line number Diff line
@@ -648,19 +648,20 @@ public final class RichInputConnection {
        // Here we test whether we indeed have a period and a space before us. This should not
        // be needed, but it's there just in case something went wrong.
        final CharSequence textBeforeCursor = getTextBeforeCursor(2, 0);
        if (!". ".equals(textBeforeCursor)) {
        final String periodSpace = ". ";
        if (!periodSpace.equals(textBeforeCursor)) {
            // Theoretically we should not be coming here if there isn't ". " before the
            // cursor, but the application may be changing the text while we are typing, so
            // anything goes. We should not crash.
            Log.d(TAG, "Tried to revert double-space combo but we didn't find "
                    + "\". \" just before the cursor.");
                    + "\"" + periodSpace + "\" just before the cursor.");
            return false;
        }
        deleteSurroundingText(2, 0);
        final String doubleSpace = "  ";
        commitText(doubleSpace, 1);
        if (ProductionFlag.IS_EXPERIMENTAL) {
            ResearchLogger.richInputConnection_revertDoubleSpacePeriod(doubleSpace);
            ResearchLogger.richInputConnection_revertDoubleSpacePeriod();
        }
        return true;
    }
@@ -685,7 +686,7 @@ public final class RichInputConnection {
        final String text = " " + textBeforeCursor.subSequence(0, 1);
        commitText(text, 1);
        if (ProductionFlag.IS_EXPERIMENTAL) {
            ResearchLogger.richInputConnection_revertSwapPunctuation(text);
            ResearchLogger.richInputConnection_revertSwapPunctuation();
        }
        return true;
    }
+9 −0
Original line number Diff line number Diff line
@@ -72,6 +72,15 @@ public class FixedLogBuffer extends LogBuffer {
        mNumActualWords++; // Must be a word, or we wouldn't be here.
    }

    @Override
    public LogUnit unshiftIn() {
        final LogUnit logUnit = super.unshiftIn();
        if (logUnit != null && logUnit.hasWord()) {
            mNumActualWords--;
        }
        return logUnit;
    }

    private void shiftOutThroughFirstWord() {
        final LinkedList<LogUnit> logUnits = getLogUnits();
        while (!logUnits.isEmpty()) {
+14 −0
Original line number Diff line number Diff line
@@ -46,6 +46,20 @@ public class LogBuffer {
        mLogUnits.add(logUnit);
    }

    public LogUnit unshiftIn() {
        if (mLogUnits.isEmpty()) {
            return null;
        }
        return mLogUnits.removeLast();
    }

    public LogUnit peekLastLogUnit() {
        if (mLogUnits.isEmpty()) {
            return null;
        }
        return mLogUnits.peekLast();
    }

    public boolean isEmpty() {
        return mLogUnits.isEmpty();
    }
+10 −0
Original line number Diff line number Diff line
@@ -240,6 +240,7 @@ import java.util.Map;
    public LogUnit splitByTime(final long maxTime) {
        // Assume that mTimeList is in sorted order.
        final int length = mTimeList.size();
        // TODO: find time by binary search, e.g. using Collections#binarySearch()
        for (int index = 0; index < length; index++) {
            if (mTimeList.get(index) > maxTime) {
                final List<LogStatement> laterLogStatements =
@@ -267,4 +268,13 @@ import java.util.Map;
        }
        return new LogUnit();
    }

    public void append(final LogUnit logUnit) {
        mLogStatementList.addAll(logUnit.mLogStatementList);
        mValuesList.addAll(logUnit.mValuesList);
        mTimeList.addAll(logUnit.mTimeList);
        mWord = null;
        mMayContainDigit = mMayContainDigit || logUnit.mMayContainDigit;
        mIsPartOfMegaword = false;
    }
}
Loading