From 3e3a41e02588256e161062108a7557a459d85e45 Mon Sep 17 00:00:00 2001 From: WhiredPlanck Date: Fri, 6 Mar 2026 22:50:18 +0800 Subject: [PATCH] refactor: send KEYCODE_ENTER instead of commit "\n" when pressing enter on virtual keyboard Fix some misbehavior editors with non-empty IME_ACTION_* but also IME_FLAG_NO_ENTER_ACTION: just let the editor handle enter key itself Close #1939 Ref: https://github.com/fcitx5-android/fcitx5-android/commit/61e10af132e858919c9749d181f8dd79c8f25f0b --- .../trime/ime/core/TrimeInputMethodService.kt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/osfans/trime/ime/core/TrimeInputMethodService.kt b/app/src/main/java/com/osfans/trime/ime/core/TrimeInputMethodService.kt index 221a68a9b5..0e7a52b630 100644 --- a/app/src/main/java/com/osfans/trime/ime/core/TrimeInputMethodService.kt +++ b/app/src/main/java/com/osfans/trime/ime/core/TrimeInputMethodService.kt @@ -298,21 +298,20 @@ open class TrimeInputMethodService : LifecycleInputMethodService() { private fun handleReturnKey() { currentInputEditorInfo.run { - if (inputType and InputType.TYPE_MASK_CLASS == InputType.TYPE_NULL) { + if (inputType and InputType.TYPE_MASK_CLASS == InputType.TYPE_NULL || + imeOptions.hasFlag(EditorInfo.IME_FLAG_NO_ENTER_ACTION) + ) { sendDownUpKeyEvents(KeyEvent.KEYCODE_ENTER) return } - if (imeOptions.hasFlag(EditorInfo.IME_FLAG_NO_ENTER_ACTION)) { - val ic = currentInputConnection - ic?.commitText("\n", 1) - return - } if (!actionLabel.isNullOrEmpty() && actionId != EditorInfo.IME_ACTION_UNSPECIFIED) { currentInputConnection.performEditorAction(actionId) return } when (val action = imeOptions and EditorInfo.IME_MASK_ACTION) { - EditorInfo.IME_ACTION_UNSPECIFIED, EditorInfo.IME_ACTION_NONE -> currentInputConnection.commitText("\n", 1) + EditorInfo.IME_ACTION_UNSPECIFIED, + EditorInfo.IME_ACTION_NONE, + -> sendDownUpKeyEvents(KeyEvent.KEYCODE_ENTER) else -> currentInputConnection.performEditorAction(action) } }