From 6334470f81bdf003b8567af9e3531cec4dce560d Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Mon, 28 Nov 2016 00:26:37 +0100 Subject: [PATCH] Try to handle Samsung keyboard better The stock Samsung keyboard with 'Auto check spelling' enabled may send multiple backspaces. Note that this auto-correction of spelling will not work good in general with a terminal, so should be disabled (or another keyboard used) when using Termux. --- app/src/main/java/com/termux/view/TerminalView.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/termux/view/TerminalView.java b/app/src/main/java/com/termux/view/TerminalView.java index 803b4c2a..e0f522ed 100644 --- a/app/src/main/java/com/termux/view/TerminalView.java +++ b/app/src/main/java/com/termux/view/TerminalView.java @@ -270,16 +270,15 @@ public final class TerminalView extends View { @Override public boolean deleteSurroundingText(int leftLength, int rightLength) { - if (LOG_KEY_EVENTS) + if (LOG_KEY_EVENTS) { Log.i(EmulatorDebug.LOG_TAG, "IME: deleteSurroundingText(" + leftLength + ", " + rightLength + ")"); - // If leftLength=2 it may be due to a UTF-16 surrogate pair. So we cannot send - // multiple key events for that. Let's just hope that keyboards don't use - // leftLength > 1 for other purposes (such as holding down backspace for repeat). - sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL)); + } + // The stock Samsung keyboard with 'Auto check spelling' enabled sends leftLength > 1. + KeyEvent deleteKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL); + for (int i = 0; i < leftLength; i++) sendKeyEvent(deleteKey); return super.deleteSurroundingText(leftLength, rightLength); } - void sendTextToTerminal(CharSequence text) { final int textLengthInChars = text.length(); for (int i = 0; i < textLengthInChars; i++) {