use a more reliable way of moving the cursor at swiping Space
This commit is contained in:
parent
2b140744eb
commit
2702350471
|
@ -187,18 +187,24 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun moveCursorRight() {
|
override fun moveCursorLeft() {
|
||||||
currentInputConnection?.apply {
|
moveCursor(false)
|
||||||
sendKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_RIGHT))
|
|
||||||
sendKeyEvent(KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_RIGHT))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun moveCursorLeft() {
|
override fun moveCursorRight() {
|
||||||
currentInputConnection?.apply {
|
moveCursor(true)
|
||||||
sendKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_LEFT))
|
}
|
||||||
sendKeyEvent(KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_LEFT))
|
|
||||||
|
private fun moveCursor(moveRight: Boolean) {
|
||||||
|
val extractedText = currentInputConnection?.getExtractedText(ExtractedTextRequest(), 0) ?: return
|
||||||
|
var newCursorPosition = extractedText.selectionStart
|
||||||
|
newCursorPosition = if (moveRight) {
|
||||||
|
newCursorPosition + 1
|
||||||
|
} else {
|
||||||
|
newCursorPosition - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentInputConnection?.setSelection(newCursorPosition, newCursorPosition)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onText(text: CharSequence?) {}
|
override fun onText(text: CharSequence?) {}
|
||||||
|
|
Loading…
Reference in New Issue