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 74d33ae149..1de2fb915f 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 @@ -101,6 +101,7 @@ open class TrimeInputMethodService : LifecycleInputMethodService() { private var mCompositionPopupWindow: CompositionPopupWindow? = null var candidateExPage = false + var shouldUpdateRimeOption = false var shouldResetAsciiMode = false private val cursorCapsMode: Int @@ -185,12 +186,16 @@ open class TrimeInputMethodService : LifecycleInputMethodService() { val theme = ThemeManager.activeTheme shouldResetAsciiMode = theme.generalStyle.resetASCIIMode isAutoCaps = theme.generalStyle.autoCaps.toBoolean() + shouldUpdateRimeOption = true } private fun updateRimeOption(): Boolean { try { - Rime.setOption("soft_cursor", prefs.keyboard.softCursorEnabled) // 軟光標 - Rime.setOption("_horizontal", ThemeManager.activeTheme.generalStyle.horizontal) // 水平模式 + if (shouldUpdateRimeOption) { + Rime.setOption("soft_cursor", prefs.keyboard.softCursorEnabled) // 軟光標 + Rime.setOption("_horizontal", ThemeManager.activeTheme.generalStyle.horizontal) // 水平模式 + shouldUpdateRimeOption = false + } } catch (e: Exception) { Timber.e(e) return false @@ -324,6 +329,7 @@ open class TrimeInputMethodService : LifecycleInputMethodService() { loadConfig() KeyboardSwitcher.newOrReset() + shouldUpdateRimeOption = true // 不能在Rime.onMessage中調用set_option,會卡死 bindKeyboardToInputView() updateComposing() // 切換主題時刷新候選 setInputView(inputView!!) diff --git a/app/src/main/java/com/osfans/trime/ime/text/TextInputManager.kt b/app/src/main/java/com/osfans/trime/ime/text/TextInputManager.kt index 9536c7d837..4d74c63abb 100644 --- a/app/src/main/java/com/osfans/trime/ime/text/TextInputManager.kt +++ b/app/src/main/java/com/osfans/trime/ime/text/TextInputManager.kt @@ -64,6 +64,11 @@ class TextInputManager( var needSendUpRimeKey: Boolean = false var isComposable: Boolean = false + private var shouldUpdateRimeOption + get() = trime.shouldUpdateRimeOption + set(value) { + trime.shouldUpdateRimeOption = value + } private val shouldResetAsciiMode get() = trime.shouldResetAsciiMode // TODO: move things using this context to InputView scope. @@ -231,8 +236,10 @@ class TextInputManager( KeyboardSwitcher.switchKeyboard(keyboard) trime.bindKeyboardToInputView() } else if (option.startsWith("_key_") && option.length > 5 && value) { + shouldUpdateRimeOption = false // 防止在 handleRimeNotification 中 setOption val key = option.substring(5) onEvent(EventManager.getEvent(key)) + shouldUpdateRimeOption = true } } } @@ -252,8 +259,11 @@ class TextInputManager( ", Event.getRimeEvent=" + Event.getRimeEvent(keyEventCode, Rime.META_RELEASE_ON), ) if (needSendUpRimeKey) { - Rime.setOption("soft_cursors", prefs.keyboard.softCursorEnabled) - Rime.setOption("_horizontal", ThemeManager.activeTheme.generalStyle.horizontal) + if (shouldUpdateRimeOption) { + Rime.setOption("soft_cursors", prefs.keyboard.softCursorEnabled) + Rime.setOption("_horizontal", ThemeManager.activeTheme.generalStyle.horizontal) + shouldUpdateRimeOption = false + } // todo 释放按键可能不对 val event = Event.getRimeEvent(keyEventCode, Rime.META_RELEASE_ON) Rime.processKey(event[0], event[1])