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 f920b3a02f..a8537a40ab 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 @@ -99,6 +99,9 @@ open class TrimeInputMethodService : LifecycleInputMethodService() { private var mCompositionPopupWindow: CompositionPopupWindow? = null var candidateExPage = false + var shouldUpdateRimeOption = false + var shouldResetAsciiMode = false + private val cursorCapsMode: Int get() = currentInputEditorInfo.run { @@ -175,17 +178,17 @@ open class TrimeInputMethodService : LifecycleInputMethodService() { fun loadConfig() { val theme = ThemeManager.activeTheme - textInputManager!!.shouldResetAsciiMode = theme.style.getBoolean("reset_ascii_mode") + shouldResetAsciiMode = theme.style.getBoolean("reset_ascii_mode") isAutoCaps = theme.style.getBoolean("auto_caps") - textInputManager!!.shouldUpdateRimeOption = true + shouldUpdateRimeOption = true } private fun updateRimeOption(): Boolean { try { - if (textInputManager!!.shouldUpdateRimeOption) { + if (shouldUpdateRimeOption) { Rime.setOption("soft_cursor", prefs.keyboard.softCursorEnabled) // 軟光標 Rime.setOption("_horizontal", ThemeManager.activeTheme.style.getBoolean("horizontal")) // 水平模式 - textInputManager!!.shouldUpdateRimeOption = false + shouldUpdateRimeOption = false } } catch (e: Exception) { e.printStackTrace() @@ -326,11 +329,9 @@ open class TrimeInputMethodService : LifecycleInputMethodService() { loadConfig() KeyboardSwitcher.newOrReset() - if (textInputManager != null) { - textInputManager!!.shouldUpdateRimeOption = true // 不能在Rime.onMessage中調用set_option,會卡死 - bindKeyboardToInputView() - updateComposing() // 切換主題時刷新候選 - } + 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 b724a377aa..bc785c02da 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 @@ -63,9 +63,14 @@ class TextInputManager private constructor() : val locales = Array(2) { Locale.getDefault() } var needSendUpRimeKey: Boolean = false - var shouldUpdateRimeOption: Boolean = true var isComposable: Boolean = false - var shouldResetAsciiMode: Boolean = false + + private var shouldUpdateRimeOption + get() = trime.shouldUpdateRimeOption + set(value) { + trime.shouldUpdateRimeOption = value + } + private val shouldResetAsciiMode get() = trime.shouldResetAsciiMode companion object { /** Delimiter regex for key property group, their format like `{property_1: value_1, property_2: value_2}` */