Skip to content

Commit

Permalink
better swipe to delete word (#725)
Browse files Browse the repository at this point in the history
* Added adaptive icon.

* better word delete
  • Loading branch information
pxeemo authored Feb 17, 2024
1 parent 57dde7d commit aef51ae
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions app/src/main/java/com/dessalines/thumbkey/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -794,23 +794,19 @@ fun isUriOrEmailOrPasswordField(ime: IMEService): Boolean {
fun deleteWordBeforeCursor(ime: IMEService) {
val wordsBeforeCursor = ime.currentInputConnection.getTextBeforeCursor(9999, 0)

val trailingSpacesLength = wordsBeforeCursor?.length?.minus(wordsBeforeCursor.trimEnd().length) ?: 0
val trimmed = wordsBeforeCursor?.trim()
val lastWordLength = trimmed?.split("\\s".toRegex())?.lastOrNull()?.length ?: 1
val minDelete = lastWordLength + trailingSpacesLength
val pattern = Regex("(\\w+\\W?|[^\\s\\w]+)?\\s*$")
val lastWordLength = wordsBeforeCursor?.let { pattern.find(it)?.value?.length } ?: 0

ime.currentInputConnection.deleteSurroundingText(minDelete, 0)
ime.currentInputConnection.deleteSurroundingText(lastWordLength, 0)
}

fun deleteWordAfterCursor(ime: IMEService) {
val wordsAfterCursor = ime.currentInputConnection.getTextAfterCursor(9999, 0)

val trailingSpacesLength = wordsAfterCursor?.length?.minus(wordsAfterCursor.trimStart().length) ?: 0
val trimmed = wordsAfterCursor?.trim()
val nextWordLength = trimmed?.split("\\s".toRegex())?.firstOrNull()?.length ?: 1
val minDelete = nextWordLength + trailingSpacesLength
val pattern = Regex("^\\s?(\\w+\\W?|[^\\s\\w]+|\\s+)")
val nextWordLength = wordsAfterCursor?.let { pattern.find(it)?.value?.length } ?: 0

ime.currentInputConnection.deleteSurroundingText(0, minDelete)
ime.currentInputConnection.deleteSurroundingText(0, nextWordLength)
}

fun buildTapActions(keyItem: KeyItemC): List<KeyAction> {
Expand Down

0 comments on commit aef51ae

Please sign in to comment.