Skip to content

Commit

Permalink
fix: could only turn the candidate page once
Browse files Browse the repository at this point in the history
Revert the removing of the judgment of whether the rime options should be updated.
  • Loading branch information
WhiredPlanck committed Apr 25, 2024
1 parent 5f946c0 commit a7e88e5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -324,6 +329,7 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {

loadConfig()
KeyboardSwitcher.newOrReset()
shouldUpdateRimeOption = true // 不能在Rime.onMessage中調用set_option,會卡死
bindKeyboardToInputView()
updateComposing() // 切換主題時刷新候選
setInputView(inputView!!)
Expand Down
14 changes: 12 additions & 2 deletions app/src/main/java/com/osfans/trime/ime/text/TextInputManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
}
}
Expand All @@ -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])
Expand Down

0 comments on commit a7e88e5

Please sign in to comment.