From 7da3aca2c716867897a577b1743ed0aadfbf935c Mon Sep 17 00:00:00 2001 From: Imanol Fernandez Date: Wed, 20 Nov 2019 11:54:03 +0100 Subject: [PATCH] Do not erase the entire text when backspace is long-pressed --- .../vrbrowser/ui/widgets/KeyboardWidget.java | 35 +++++++------------ 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/KeyboardWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/KeyboardWidget.java index d8d99c88a..9e7b3605e 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/KeyboardWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/KeyboardWidget.java @@ -463,8 +463,6 @@ public void onLongPress(Keyboard.Key popupKey) { } else if (popupKey.codes[0] == CustomKeyboard.KEYCODE_SHIFT) { mIsLongPress = !mIsCapsLock; - } else if (popupKey.codes[0] == Keyboard.KEYCODE_DELETE) { - handleBackspace(true); } } @@ -489,7 +487,7 @@ public void onKey(int primaryCode, int[] keyCodes, boolean hasPopup) { handleShift(!mKeyboardView.isShifted()); break; case Keyboard.KEYCODE_DELETE: - handleBackspace(false); + handleBackspace(); break; case Keyboard.KEYCODE_DONE: handleDone(); @@ -645,7 +643,7 @@ private void handleShift(boolean isShifted) { mKeyboardView.setShifted(shifted || mIsCapsLock); } - private void handleBackspace(final boolean isLongPress) { + private void handleBackspace() { final InputConnection connection = mInputConnection; if (mComposingText.length() > 0) { CharSequence selectedText = mInputConnection.getSelectedText(0); @@ -668,25 +666,18 @@ private void handleBackspace(final boolean isLongPress) { return; } - if (isLongPress) { - CharSequence currentText = connection.getExtractedText(new ExtractedTextRequest(), 0).text; - CharSequence beforeCursorText = connection.getTextBeforeCursor(currentText.length(), 0); - CharSequence afterCursorText = connection.getTextAfterCursor(currentText.length(), 0); - connection.deleteSurroundingText(beforeCursorText.length(), afterCursorText.length()); - } else { - if (mCurrentKeyboard.usesTextOverride()) { - String beforeText = getTextBeforeCursor(connection); - String newBeforeText = mCurrentKeyboard.overrideBackspace(beforeText); - if (newBeforeText != null) { - // Replace whole before text - connection.deleteSurroundingText(beforeText.length(), 0); - connection.commitText(newBeforeText, 1); - return; - } + if (mCurrentKeyboard.usesTextOverride()) { + String beforeText = getTextBeforeCursor(connection); + String newBeforeText = mCurrentKeyboard.overrideBackspace(beforeText); + if (newBeforeText != null) { + // Replace whole before text + connection.deleteSurroundingText(beforeText.length(), 0); + connection.commitText(newBeforeText, 1); + return; } - // Remove the character before the cursor. - connection.deleteSurroundingText(1, 0); } + // Remove the character before the cursor. + connection.deleteSurroundingText(1, 0); }); } @@ -1030,7 +1021,7 @@ public boolean dispatchKeyEvent(final KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_DEL: - handleBackspace(event.isLongPress()); + handleBackspace(); return true; case KeyEvent.KEYCODE_ENTER: case KeyEvent.KEYCODE_NUMPAD_ENTER: