From ff524bc662aab0fd19bae16d54af3808b98500e1 Mon Sep 17 00:00:00 2001 From: WhiredPlanck Date: Mon, 11 Nov 2024 22:33:44 +0800 Subject: [PATCH] fix: temporary workaround for duplicated return action (again) --- .../osfans/trime/ime/core/TrimeInputMethodService.kt | 10 +++++++++- .../trime/ime/keyboard/CommonKeyboardActionListener.kt | 3 +-- 2 files changed, 10 insertions(+), 3 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 a57bc254e3..80dc761e82 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 @@ -274,6 +274,14 @@ open class TrimeInputMethodService : LifecycleInputMethodService() { is RimeEvent.KeyEvent -> it.data.let event@{ val keyCode = it.value.keyCode + // TODO: look for better workaround for this + if (it.modifiers == KeyModifiers.Empty) { + when (keyCode) { + KeyEvent.KEYCODE_ENTER -> handleReturnKey() + else -> commitText(Char(it.unicode).toString()) + } + return@event + } if (keyCode != KeyEvent.KEYCODE_UNKNOWN) { val eventTime = SystemClock.uptimeMillis() if (it.up) { @@ -318,7 +326,7 @@ open class TrimeInputMethodService : LifecycleInputMethodService() { instance = null } - fun handleReturnKey() { + private fun handleReturnKey() { currentInputEditorInfo.run { if (inputType and InputType.TYPE_MASK_CLASS == InputType.TYPE_NULL) { sendDownUpKeyEvents(KeyEvent.KEYCODE_ENTER) diff --git a/app/src/main/java/com/osfans/trime/ime/keyboard/CommonKeyboardActionListener.kt b/app/src/main/java/com/osfans/trime/ime/keyboard/CommonKeyboardActionListener.kt index b257354d42..2e5d76d525 100644 --- a/app/src/main/java/com/osfans/trime/ime/keyboard/CommonKeyboardActionListener.kt +++ b/app/src/main/java/com/osfans/trime/ime/keyboard/CommonKeyboardActionListener.kt @@ -279,8 +279,7 @@ class CommonKeyboardActionListener( shouldReleaseKey = false when (keyEventCode) { - KeyEvent.KEYCODE_ENTER -> service.handleReturnKey() - KeyEvent.KEYCODE_BACK, KeyEvent.KEYCODE_ESCAPE -> service.requestHideSelf(0) + KeyEvent.KEYCODE_BACK -> service.requestHideSelf(0) else -> { // 小键盘自动增加锁定 if (keyEventCode in KeyEvent.KEYCODE_NUMPAD_0..KeyEvent.KEYCODE_NUMPAD_EQUALS) {