Bug 1888378 - Commit url on numpad ENTER too. r=android-reviewers,mcarare

Differential Revision: https://phabricator.services.mozilla.com/D206002
This commit is contained in:
jackyzy823 2024-04-16 06:45:22 +00:00
Родитель 61d13ab945
Коммит 25d431d79c
2 изменённых файлов: 13 добавлений и 2 удалений

Просмотреть файл

@ -182,7 +182,7 @@ open class InlineAutocompleteEditText @JvmOverloads constructor(
return false
}
if (keyCode == KeyEvent.KEYCODE_ENTER) {
if (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_NUMPAD_ENTER) {
// If the edit text has a composition string, don't submit the text yet.
// ENTER is needed to commit the composition string.
val content = text
@ -201,7 +201,7 @@ open class InlineAutocompleteEditText @JvmOverloads constructor(
}
private val onKey = fun (_: View, keyCode: Int, event: KeyEvent): Boolean {
if (keyCode == KeyEvent.KEYCODE_ENTER) {
if (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_NUMPAD_ENTER) {
if (event.action != KeyEvent.ACTION_DOWN) {
return true
}

Просмотреть файл

@ -226,6 +226,17 @@ class InlineAutocompleteEditTextTest {
assertTrue(invoked)
}
@Test
fun `onCommitListenerInvocation with Numpad ENTER`() {
val et = InlineAutocompleteEditText(testContext, attributes)
var invoked = false
et.setOnCommitListener { invoked = true }
et.onAttachedToWindow()
et.dispatchKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_NUMPAD_ENTER))
assertTrue(invoked)
}
@Test
fun onTextChangeListenerInvocation() {
val et = InlineAutocompleteEditText(testContext, attributes)