Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 289ee63

Browse files
MortimerGorobluemarvin
authored andcommitted
Do not erase the entire text when backspace is long-pressed (#2324)
1 parent 5811237 commit 289ee63

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/KeyboardWidget.java

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,6 @@ public void onLongPress(Keyboard.Key popupKey) {
463463
} else if (popupKey.codes[0] == CustomKeyboard.KEYCODE_SHIFT) {
464464
mIsLongPress = !mIsCapsLock;
465465

466-
} else if (popupKey.codes[0] == Keyboard.KEYCODE_DELETE) {
467-
handleBackspace(true);
468466
}
469467
}
470468

@@ -489,7 +487,7 @@ public void onKey(int primaryCode, int[] keyCodes, boolean hasPopup) {
489487
handleShift(!mKeyboardView.isShifted());
490488
break;
491489
case Keyboard.KEYCODE_DELETE:
492-
handleBackspace(false);
490+
handleBackspace();
493491
break;
494492
case Keyboard.KEYCODE_DONE:
495493
handleDone();
@@ -645,7 +643,7 @@ private void handleShift(boolean isShifted) {
645643
mKeyboardView.setShifted(shifted || mIsCapsLock);
646644
}
647645

648-
private void handleBackspace(final boolean isLongPress) {
646+
private void handleBackspace() {
649647
final InputConnection connection = mInputConnection;
650648
if (mComposingText.length() > 0) {
651649
CharSequence selectedText = mInputConnection.getSelectedText(0);
@@ -668,25 +666,18 @@ private void handleBackspace(final boolean isLongPress) {
668666
return;
669667
}
670668

671-
if (isLongPress) {
672-
CharSequence currentText = connection.getExtractedText(new ExtractedTextRequest(), 0).text;
673-
CharSequence beforeCursorText = connection.getTextBeforeCursor(currentText.length(), 0);
674-
CharSequence afterCursorText = connection.getTextAfterCursor(currentText.length(), 0);
675-
connection.deleteSurroundingText(beforeCursorText.length(), afterCursorText.length());
676-
} else {
677-
if (mCurrentKeyboard.usesTextOverride()) {
678-
String beforeText = getTextBeforeCursor(connection);
679-
String newBeforeText = mCurrentKeyboard.overrideBackspace(beforeText);
680-
if (newBeforeText != null) {
681-
// Replace whole before text
682-
connection.deleteSurroundingText(beforeText.length(), 0);
683-
connection.commitText(newBeforeText, 1);
684-
return;
685-
}
669+
if (mCurrentKeyboard.usesTextOverride()) {
670+
String beforeText = getTextBeforeCursor(connection);
671+
String newBeforeText = mCurrentKeyboard.overrideBackspace(beforeText);
672+
if (newBeforeText != null) {
673+
// Replace whole before text
674+
connection.deleteSurroundingText(beforeText.length(), 0);
675+
connection.commitText(newBeforeText, 1);
676+
return;
686677
}
687-
// Remove the character before the cursor.
688-
connection.deleteSurroundingText(1, 0);
689678
}
679+
// Remove the character before the cursor.
680+
connection.deleteSurroundingText(1, 0);
690681
});
691682
}
692683

@@ -1030,7 +1021,7 @@ public boolean dispatchKeyEvent(final KeyEvent event) {
10301021

10311022
switch (keyCode) {
10321023
case KeyEvent.KEYCODE_DEL:
1033-
handleBackspace(event.isLongPress());
1024+
handleBackspace();
10341025
return true;
10351026
case KeyEvent.KEYCODE_ENTER:
10361027
case KeyEvent.KEYCODE_NUMPAD_ENTER:

0 commit comments

Comments
 (0)