Skip to content

Commit 6c8f031

Browse files
Henry-ZHRBambooin
authored andcommitted
fix: ascii_mode not being set correctly
Before: `ascii_mode` is set to `0` every time the keyboard is shown (most cases) Now: follows user's setting (`reset_ascii_mode`, etc)
1 parent bb6cb34 commit 6c8f031

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

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

+3-10
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ class TextInputManager private constructor() :
6161
var shouldUpdateRimeOption: Boolean = true
6262
var performEnterAsLineBreak: Boolean = false
6363
var isComposable: Boolean = false
64-
var isAsciiMode: Boolean = true
65-
var isTempAsciiMode: Boolean = true
6664
var shouldResetAsciiMode: Boolean = false
6765

6866
companion object {
@@ -179,7 +177,7 @@ class TextInputManager private constructor() :
179177
super.onStartInputView(instance, restarting)
180178
isComposable = false
181179
performEnterAsLineBreak = false
182-
var tempAsciiMode = false
180+
var tempAsciiMode = if (shouldResetAsciiMode) false else null
183181
val inputAttrsRaw = instance.editorInfo!!.inputType
184182
val keyboardType = when (inputAttrsRaw and InputType.TYPE_MASK_CLASS) {
185183
InputType.TYPE_CLASS_NUMBER,
@@ -220,7 +218,7 @@ class TextInputManager private constructor() :
220218
it.switchToKeyboard(keyboardType)
221219
}
222220
Rime.get(trime)
223-
Rime.setOption("ascii_mode", tempAsciiMode)
221+
tempAsciiMode?.let { Rime.setOption("ascii_mode", it) }
224222
isComposable = isComposable && !Rime.isEmpty()
225223
if (!trime.onEvaluateInputViewShown()) {
226224
// Show candidate view when using physical keyboard
@@ -231,9 +229,6 @@ class TextInputManager private constructor() :
231229
fun onOptionChanged(option: String, value: Boolean) {
232230
when (option) {
233231
"ascii_mode" -> {
234-
if (!isTempAsciiMode) {
235-
isAsciiMode = value // 切換中西文時保存狀態
236-
}
237232
trime.inputFeedbackManager.ttsLanguage =
238233
locales[if (value) 1 else 0]
239234
}
@@ -249,7 +244,6 @@ class TextInputManager private constructor() :
249244
) {
250245
val keyboard = option.substring(10)
251246
keyboardSwitcher.switchToKeyboard(keyboard)
252-
isTempAsciiMode = keyboardSwitcher.asciiMode
253247
trime.bindKeyboardToInputView()
254248
} else if (option.startsWith("_key_") && option.length > 5 && value) {
255249
shouldUpdateRimeOption = false // 防止在 onMessage 中 setOption
@@ -307,8 +301,7 @@ class TextInputManager private constructor() :
307301
KeyEvent.KEYCODE_EISU -> { // Switch keyboard
308302
keyboardSwitcher.switchToKeyboard(event.select)
309303
/** Set ascii mode according to keyboard's settings, can not place into [Rime.onMessage] */
310-
isTempAsciiMode = keyboardSwitcher.asciiMode
311-
Rime.setOption("ascii_mode", isTempAsciiMode)
304+
Rime.setOption("ascii_mode", keyboardSwitcher.asciiMode)
312305
trime.bindKeyboardToInputView()
313306
trime.updateComposing()
314307
}

0 commit comments

Comments
 (0)