Make the backspace key remove text directly instead of sending a DEL keycode (#1162)

This commit is contained in:
Paul Kramer 2024-11-29 15:17:35 +01:00 committed by GitHub
parent ac514dad22
commit 9c08defdef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 8 deletions

View File

@ -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,
),

View File

@ -164,6 +164,8 @@ sealed class KeyAction {
data object CycleRight : KeyAction()
}
data object DeleteKeyAction : KeyAction()
data object DeleteWordBeforeCursor : KeyAction()
data object DeleteWordAfterCursor : KeyAction()

View File

@ -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)