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

Commit 68b54b48 authored by Glenn Maynard's avatar Glenn Maynard
Browse files

Delete a word by pressing shift-backspace.



Change-Id: I19360bc3cf39e90756a1399bd2f01a3a09296983
Signed-off-by: default avatarGlenn Maynard <glenn@zewt.org>
parent 6dfe4fa5
Loading
Loading
Loading
Loading
+62 −4
Original line number Diff line number Diff line
@@ -1285,6 +1285,46 @@ public class LatinIME extends InputMethodService
        mKeyboardSwitcher.onCancelInput();
    }

    private void backspaceWord(InputConnection ic) {
        CharSequence chars = ic.getTextBeforeCursor(256, 0);
        if (chars == null || chars.length() == 0)
            return;

        Log.d(TAG, "Text (" + chars.length() + "): \"" + chars.toString() + "\"");

        // Always delete at least one character.
        int lastCharToDelete = chars.length() - 1;

        // Delete consecutive separators at the end, eg. "text...".
        if (isWordSeparator(chars.charAt(lastCharToDelete))) {
            while (lastCharToDelete > 0) {
                char c = chars.charAt(lastCharToDelete-1);
                if (!isWordSeparator(c))
                    break;
                --lastCharToDelete;
            }
        }

        // Delete all consecutive non-word-separators at the cursor.
        while (lastCharToDelete > 0) {
            char c = chars.charAt(lastCharToDelete-1);
            if (isWordSeparator(c))
                break;
            --lastCharToDelete;
        }

        int charsToDelete = chars.length() - lastCharToDelete;

        // If mEnteredText is set, always delete the entire string.
        if (mEnteredText != null && sameAsTextBeforeCursor(ic, mEnteredText)) {
            if (mEnteredText.length() > charsToDelete)
                charsToDelete = mEnteredText.length();
        }

        Log.d(TAG, "Backspace " + charsToDelete + " chars");
        ic.deleteSurroundingText(charsToDelete, 0);
    }

    private void handleBackspace() {
        if (VOICE_INSTALLED && mVoiceInputHighlighted) {
            mVoiceInput.incrementTextModificationDeleteCount(
@@ -1310,7 +1350,25 @@ public class LatinIME extends InputMethodService
            }
        }

        if (mPredicting) {
        // On shift-backspace, delete a word.
        if (mShiftKeyState.isMomentary()) {
            // If we're composing, finalize it.
            mComposing.setLength(0);
            ic.finishComposingText();
            mWord.reset();
            mVoiceInputHighlighted = false;
            mPredicting = false;

            // In case we're in "touch again to save":
            mCandidateView.clear();

            TextEntryState.reset();

            backspaceWord(ic);

            // Make sure we don't delete mEnteredText again below.
            mEnteredText = null;
        } else if (mPredicting) {
            final int length = mComposing.length();
            if (length > 0) {
                mComposing.delete(length - 1, length);
@@ -2309,8 +2367,8 @@ public class LatinIME extends InputMethodService
            mSymbolKeyState.onPress();
            mKeyboardSwitcher.setAutoModeSwitchStateMomentary();
        } else {
            mShiftKeyState.onOtherKeyPressed();
            mSymbolKeyState.onOtherKeyPressed();
            mShiftKeyState.onOtherKeyPressed(primaryCode);
            mSymbolKeyState.onOtherKeyPressed(primaryCode);
        }
    }

@@ -2320,7 +2378,7 @@ public class LatinIME extends InputMethodService
        //vibrate();
        final boolean distinctMultiTouch = mKeyboardSwitcher.hasDistinctMultitouch();
        if (distinctMultiTouch && primaryCode == Keyboard.KEYCODE_SHIFT) {
            if (mShiftKeyState.isMomentary())
            if (mShiftKeyState.isMomentary() && mShiftKeyState.getOtherKeyCode() != Keyboard.KEYCODE_DELETE)
                resetShift();
            mShiftKeyState.onRelease();
        } else if (distinctMultiTouch && primaryCode == Keyboard.KEYCODE_MODE_CHANGE) {
+9 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ class ModifierKeyState {
    private static final int MOMENTARY = 2;

    private int mState = RELEASING;
    private int mMomentaryOtherKeyCode;

    public void onPress() {
        mState = PRESSING;
@@ -31,12 +32,19 @@ class ModifierKeyState {
        mState = RELEASING;
    }

    public void onOtherKeyPressed() {
    public void onOtherKeyPressed(int primaryCode) {
        if (mState == PRESSING)
	{
            mState = MOMENTARY;
            mMomentaryOtherKeyCode = primaryCode;
	}
    }

    public boolean isMomentary() {
        return mState == MOMENTARY;
    }

    public int getOtherKeyCode() {
        return mMomentaryOtherKeyCode;
    }
}