mirror of
https://github.com/fcitx5-android/fcitx5-android.git
synced 2026-08-02 20:16:06 +08:00
Use InputConnection#setSelection to move cursor when supported
This commit is contained in:
parent
d934559d94
commit
9432a18398
@ -229,8 +229,8 @@ class FcitxInputMethodService : LifecycleInputMethodService() {
|
||||
when (it.sym.sym) {
|
||||
FcitxKeyMapping.FcitxKey_BackSpace -> handleBackspaceKey()
|
||||
FcitxKeyMapping.FcitxKey_Return -> handleReturnKey()
|
||||
FcitxKeyMapping.FcitxKey_Left -> sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_LEFT)
|
||||
FcitxKeyMapping.FcitxKey_Right -> sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_RIGHT)
|
||||
FcitxKeyMapping.FcitxKey_Left -> handleArrowKey(KeyEvent.KEYCODE_DPAD_LEFT)
|
||||
FcitxKeyMapping.FcitxKey_Right -> handleArrowKey(KeyEvent.KEYCODE_DPAD_RIGHT)
|
||||
else -> if (it.unicode > 0) {
|
||||
commitText(Character.toString(it.unicode))
|
||||
} else {
|
||||
@ -388,6 +388,19 @@ class FcitxInputMethodService : LifecycleInputMethodService() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleArrowKey(keyCode: Int) {
|
||||
if (currentInputEditorInfo.inputType and InputType.TYPE_MASK_CLASS == InputType.TYPE_NULL) {
|
||||
sendDownUpKeyEvents(keyCode)
|
||||
return
|
||||
}
|
||||
val target = when (keyCode) {
|
||||
KeyEvent.KEYCODE_DPAD_LEFT -> currentInputSelection.start - 1
|
||||
KeyEvent.KEYCODE_DPAD_RIGHT -> currentInputSelection.end + 1
|
||||
else -> return
|
||||
}
|
||||
currentInputConnection.setSelection(target, target)
|
||||
}
|
||||
|
||||
fun commitText(text: String, cursor: Int = -1) {
|
||||
val ic = currentInputConnection ?: return
|
||||
// when composing text equals commit content, finish composing text as-is
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user