Skip to content

Commit a7e88e5

Browse files
committed
fix: could only turn the candidate page once
Revert the removing of the judgment of whether the rime options should be updated.
1 parent 5f946c0 commit a7e88e5

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

app/src/main/java/com/osfans/trime/ime/core/TrimeInputMethodService.kt

+8-2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
101101
private var mCompositionPopupWindow: CompositionPopupWindow? = null
102102
var candidateExPage = false
103103

104+
var shouldUpdateRimeOption = false
104105
var shouldResetAsciiMode = false
105106

106107
private val cursorCapsMode: Int
@@ -185,12 +186,16 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
185186
val theme = ThemeManager.activeTheme
186187
shouldResetAsciiMode = theme.generalStyle.resetASCIIMode
187188
isAutoCaps = theme.generalStyle.autoCaps.toBoolean()
189+
shouldUpdateRimeOption = true
188190
}
189191

190192
private fun updateRimeOption(): Boolean {
191193
try {
192-
Rime.setOption("soft_cursor", prefs.keyboard.softCursorEnabled) // 軟光標
193-
Rime.setOption("_horizontal", ThemeManager.activeTheme.generalStyle.horizontal) // 水平模式
194+
if (shouldUpdateRimeOption) {
195+
Rime.setOption("soft_cursor", prefs.keyboard.softCursorEnabled) // 軟光標
196+
Rime.setOption("_horizontal", ThemeManager.activeTheme.generalStyle.horizontal) // 水平模式
197+
shouldUpdateRimeOption = false
198+
}
194199
} catch (e: Exception) {
195200
Timber.e(e)
196201
return false
@@ -324,6 +329,7 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
324329

325330
loadConfig()
326331
KeyboardSwitcher.newOrReset()
332+
shouldUpdateRimeOption = true // 不能在Rime.onMessage中調用set_option,會卡死
327333
bindKeyboardToInputView()
328334
updateComposing() // 切換主題時刷新候選
329335
setInputView(inputView!!)

app/src/main/java/com/osfans/trime/ime/text/TextInputManager.kt

+12-2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ class TextInputManager(
6464
var needSendUpRimeKey: Boolean = false
6565
var isComposable: Boolean = false
6666

67+
private var shouldUpdateRimeOption
68+
get() = trime.shouldUpdateRimeOption
69+
set(value) {
70+
trime.shouldUpdateRimeOption = value
71+
}
6772
private val shouldResetAsciiMode get() = trime.shouldResetAsciiMode
6873

6974
// TODO: move things using this context to InputView scope.
@@ -231,8 +236,10 @@ class TextInputManager(
231236
KeyboardSwitcher.switchKeyboard(keyboard)
232237
trime.bindKeyboardToInputView()
233238
} else if (option.startsWith("_key_") && option.length > 5 && value) {
239+
shouldUpdateRimeOption = false // 防止在 handleRimeNotification 中 setOption
234240
val key = option.substring(5)
235241
onEvent(EventManager.getEvent(key))
242+
shouldUpdateRimeOption = true
236243
}
237244
}
238245
}
@@ -252,8 +259,11 @@ class TextInputManager(
252259
", Event.getRimeEvent=" + Event.getRimeEvent(keyEventCode, Rime.META_RELEASE_ON),
253260
)
254261
if (needSendUpRimeKey) {
255-
Rime.setOption("soft_cursors", prefs.keyboard.softCursorEnabled)
256-
Rime.setOption("_horizontal", ThemeManager.activeTheme.generalStyle.horizontal)
262+
if (shouldUpdateRimeOption) {
263+
Rime.setOption("soft_cursors", prefs.keyboard.softCursorEnabled)
264+
Rime.setOption("_horizontal", ThemeManager.activeTheme.generalStyle.horizontal)
265+
shouldUpdateRimeOption = false
266+
}
257267
// todo 释放按键可能不对
258268
val event = Event.getRimeEvent(keyEventCode, Rime.META_RELEASE_ON)
259269
Rime.processKey(event[0], event[1])

0 commit comments

Comments
 (0)