From 1eef115cb42b458a6262413491b51757c8b57169 Mon Sep 17 00:00:00 2001 From: Paul Kramer Date: Fri, 29 Nov 2024 15:11:00 +0100 Subject: [PATCH] Make the backspace key remove text directly instead of sending a DEL keycode --- .../java/com/dessalines/thumbkey/keyboards/CommonKeys.kt | 9 +-------- app/src/main/java/com/dessalines/thumbkey/utils/Types.kt | 2 ++ app/src/main/java/com/dessalines/thumbkey/utils/Utils.kt | 8 ++++++++ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/dessalines/thumbkey/keyboards/CommonKeys.kt b/app/src/main/java/com/dessalines/thumbkey/keyboards/CommonKeys.kt index 208009770..fd26d7378 100644 --- a/app/src/main/java/com/dessalines/thumbkey/keyboards/CommonKeys.kt +++ b/app/src/main/java/com/dessalines/thumbkey/keyboards/CommonKeys.kt @@ -144,14 +144,7 @@ val BACKSPACE_KEY_ITEM = center = KeyC( display = KeyDisplay.IconDisplay(Icons.AutoMirrored.Outlined.KeyboardBackspace), - action = - SendEvent( - KeyEvent( - KeyEvent.ACTION_DOWN, - KeyEvent - .KEYCODE_DEL, - ), - ), + action = DeleteKeyAction, size = LARGE, color = SECONDARY, ), diff --git a/app/src/main/java/com/dessalines/thumbkey/utils/Types.kt b/app/src/main/java/com/dessalines/thumbkey/utils/Types.kt index 87ec647f9..dd7b8eaea 100644 --- a/app/src/main/java/com/dessalines/thumbkey/utils/Types.kt +++ b/app/src/main/java/com/dessalines/thumbkey/utils/Types.kt @@ -164,6 +164,8 @@ sealed class KeyAction { data object CycleRight : KeyAction() } + data object DeleteKeyAction : KeyAction() + data object DeleteWordBeforeCursor : KeyAction() data object DeleteWordAfterCursor : KeyAction() diff --git a/app/src/main/java/com/dessalines/thumbkey/utils/Utils.kt b/app/src/main/java/com/dessalines/thumbkey/utils/Utils.kt index 3aeb93c93..a3b751654 100644 --- a/app/src/main/java/com/dessalines/thumbkey/utils/Utils.kt +++ b/app/src/main/java/com/dessalines/thumbkey/utils/Utils.kt @@ -361,6 +361,14 @@ fun performKeyAction( ime.currentInputConnection.sendKeyEvent(ev) } + is KeyAction.DeleteKeyAction -> { + if (ime.currentInputConnection.getSelectedText(0)?.isEmpty() != false) { + ime.currentInputConnection.deleteSurroundingText(1, 0) + } else { + ime.currentInputConnection.commitText("", 0) + } + } + is KeyAction.DeleteWordBeforeCursor -> { Log.d(TAG, "deleting last word") deleteWordBeforeCursor(ime)