Skip to content

Commit

Permalink
Make the backspace key remove text directly instead of sending a DEL …
Browse files Browse the repository at this point in the history
…keycode (#1162)
  • Loading branch information
gitterrost4 authored Nov 29, 2024
1 parent ac514da commit 9c08def
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/dessalines/thumbkey/utils/Types.kt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ sealed class KeyAction {
data object CycleRight : KeyAction()
}

data object DeleteKeyAction : KeyAction()

data object DeleteWordBeforeCursor : KeyAction()

data object DeleteWordAfterCursor : KeyAction()
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/com/dessalines/thumbkey/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9c08def

Please sign in to comment.