Tweak commitAndReset workaround for all languages

Chinese: select 1st candidate (excluding prediction) and reset
Others: commit preedit as-is and reset
This commit is contained in:
Rocka 2025-08-13 00:12:34 +08:00
parent 28df3f2a80
commit 1aabfbe75f
No known key found for this signature in database
GPG Key ID: 28031158FFDD6853

View File

@ -64,19 +64,19 @@ class CommonKeyActionListener :
private var backspaceSwipeState = Stopped
private val keepComposingIMs = arrayOf("keyboard-us", "unikey")
// there should be a new fcitx API for this
private suspend fun FcitxAPI.commitAndReset() {
if (clientPreeditCached.isEmpty() && inputPanelCached.preedit.isEmpty()) {
// preedit is empty, there can be prediction candidates
reset()
} else if (inputMethodEntryCached.uniqueName in keepComposingIMs) {
// androidkeyboard clears composing on reset, but we want to commit it as-is
service.finishComposing()
reset()
if (inputMethodEntryCached.languageCode.startsWith("zh")) {
// Chinese: select 1st candidate, except prediction candidates
if (clientPreeditCached.isNotEmpty() || inputPanelCached.preedit.isNotEmpty()) {
// preedit not empty, maybe there are candidates to select ...
select(0)
}
} else {
if (!select(0)) reset()
// Other languages: commit preedit as-is
service.finishComposing()
}
reset()
}
private fun showInputMethodPicker() {