Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #949 from matrix-org/fix/android-fix-half-width-en…
Browse files Browse the repository at this point in the history
…glish-in-chinese-keyboards

Android: fix English characters in some Chinese keyboards
  • Loading branch information
jmartinesp authored Mar 19, 2024
2 parents ac2e246 + 6911abf commit 5d3e6c3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.element.android.wysiwyg.inputhandlers

import android.app.Application
import android.view.KeyEvent
import android.view.inputmethod.EditorInfo
import android.widget.EditText
import androidx.test.core.app.ApplicationProvider
Expand Down Expand Up @@ -539,6 +540,20 @@ class InterceptInputConnectionIntegrationTest {
assertThat(textView.selectionEnd, equalTo(2))
}

@Test
fun testHalfWidthEnglishInChineseKeyboards() {
inputConnection.run {
sendHardwareKeyboardInput(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_T))
setComposingText("", 1)
sendHardwareKeyboardInput(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_E))
setComposingText("", 1)
sendHardwareKeyboardInput(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_S))
setComposingText("", 1)
sendHardwareKeyboardInput(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_T))
}
assertThat(textView.text.toString(), equalTo("test"))
}

private fun simulateInput(editorInputAction: EditorInputAction) =
viewModel.processInput(editorInputAction)?.let { (text, selection) ->
textView.setText(text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ internal class InterceptInputConnection(
// Called when started typing
override fun setComposingText(text: CharSequence, newCursorPosition: Int): Boolean {
val (start, end) = getCurrentCompositionOrSelection()
// Some Chinese keyboards send empty text when the user is typing English characters
if (text.isEmpty() && Selection.getSelectionStart(editable) == Selection.getSelectionEnd(editable)) {
finishComposingText()
return false
}
val result = processTextEntry(text, start, end)

return if (result != null) {
Expand Down

0 comments on commit 5d3e6c3

Please sign in to comment.