use a more reliable way of moving the cursor at swiping Space

This commit is contained in:
tibbi 2022-01-19 23:09:38 +01:00
parent 2b140744eb
commit 2702350471
1 changed files with 15 additions and 9 deletions

View File

@ -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?) {}