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

Commit 3e160bbe authored by Jean Chalard's avatar Jean Chalard
Browse files

[CB21] More refactoring

Bug: 13406701
Change-Id: I96e0a7fa2d9f4dfd8c355da4effc116bbd0f7f18
parent dfaeb125
Loading
Loading
Loading
Loading
+20 −17
Original line number Diff line number Diff line
@@ -189,11 +189,6 @@ public final class WordComposer {
                newIndex, primaryCode, mIsFirstCharCapitalized);
        if (Character.isUpperCase(primaryCode)) mCapsCount++;
        if (Character.isDigit(primaryCode)) mDigitsCount++;
        if (Constants.CODE_SINGLE_QUOTE == primaryCode) {
            ++mTrailingSingleQuotesCount;
        } else {
            mTrailingSingleQuotesCount = 0;
        }
    }

    private void processEvent(final Event event) {
@@ -209,26 +204,34 @@ public final class WordComposer {
        if (0 == mCodePointSize) {
            mIsFirstCharCapitalized = false;
        }
        mAutoCorrection = null;
    }

    /**
     * Delete the last composing unit as a result of hitting backspace.
     */
    public void deleteLast(final Event event) {
        processEvent(event);
        if (Constants.CODE_DELETE == event.mKeyCode) {
            if (mTrailingSingleQuotesCount > 0) {
                --mTrailingSingleQuotesCount;
            } else {
            int i = mTypedWordCache.length();
            while (i > 0) {
                i = Character.offsetByCodePoints(mTypedWordCache, i, -1);
                if (Constants.CODE_SINGLE_QUOTE != Character.codePointAt(mTypedWordCache, i)) {
                // Delete, but we didn't end in a quote: must recompute mTrailingSingleQuotesCount
                // We're only searching for single quotes, so no need to account for code points
                for (int i = mTypedWordCache.length() - 1; i > 0; --i) {
                    if (Constants.CODE_SINGLE_QUOTE != mTypedWordCache.charAt(i)) {
                        break;
                    }
                    ++mTrailingSingleQuotesCount;
                }
            }
        } else {
            if (Constants.CODE_SINGLE_QUOTE == primaryCode) {
                ++mTrailingSingleQuotesCount;
            } else {
                mTrailingSingleQuotesCount = 0;
            }
        }
        mAutoCorrection = null;
    }

    /**
     * Delete the last composing unit as a result of hitting backspace.
     */
    public void deleteLast(final Event event) {
        processEvent(event);
    }

    public void setCursorPositionWithinWord(final int posWithinWord) {