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 20800977..fd26d737 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 87ec647f..dd7b8eae 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 3aeb93c9..a3b75165 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)