Skip to content

Commit

Permalink
Fix #304: Improve Utils.autoCapitalizeCheck
Browse files Browse the repository at this point in the history
Instead of manually reading the `getTextBeforeCursor` manually,
use IMEService.currentInputConnection.getCursorCapsMode to detect
whether auto-capitalization should happen.
This fixes bug #304, where terminal emulator apps like Termux, JuiceSSH,
KDE Connect, etc., which provide an empty input connection to Thumb-Key,
would always be auto-capitalized.
  • Loading branch information
mpsijm committed May 11, 2024
1 parent 3693d0e commit ddbe326
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions app/src/main/java/com/dessalines/thumbkey/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.os.Build
import android.os.Handler
import android.os.Looper
import android.text.InputType
import android.text.TextUtils
import android.util.Log
import android.view.KeyEvent
import android.view.inputmethod.EditorInfo
Expand Down Expand Up @@ -1002,22 +1003,7 @@ private fun autoCapitalize(
}

fun autoCapitalizeCheck(ime: IMEService): Boolean {
return isEmptyField(ime) || isPunctuationEnd(ime)
}

/**
* Checks if the field is empty
*/
fun isEmptyField(ime: IMEService): Boolean {
return ime.currentInputConnection.getTextBeforeCursor(1, 0).isNullOrEmpty()
}

/**
* Checks if the field ends with a punctuation
*/
fun isPunctuationEnd(ime: IMEService): Boolean {
val textBefore = ime.currentInputConnection.getTextBeforeCursor(2, 0)
return (listOf(". ", "? ", "! ").contains(textBefore))
return ime.currentInputConnection.getCursorCapsMode(TextUtils.CAP_MODE_SENTENCES) > 0
}

/**
Expand Down

0 comments on commit ddbe326

Please sign in to comment.