fix(keyboard): preserve ascii_mode across keyboard switches (#1979)

When switching between keyboard layouts, ascii_mode is unconditionally
reset to the keyboard's default, discarding the user's current input
mode.

This happends due to TextKeyboard always defaults reset_ascii_mode to
true, overriding the global theme setting, and lastAsciiMode is never
saved when leaving a keyboard.

Fix this by making TextKeyboard.resetAsciiMode nullable so that unset
values fall through to the global theme settings in Keyboard, saving the
current ascii_mode before switching away. Each keyboard's resetAsciiMode
now falls back to the global setting and determines whether to reset or
restore the previous mode.

v1->v2:
 - Fix regression in KeyboardWindow::attachKeyboard()

Signed-off-by: Xavier Hsinyuan <me@lstlx.com>
This commit is contained in:
Xavier Hsinyuan 2026-04-13 20:57:07 +08:00 committed by GitHub
parent fc450aafee
commit 4b8badcbfd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 3 deletions

View File

@ -32,7 +32,7 @@ data class TextKeyboard(
val keyBorder: Int,
val columns: Int,
val asciiMode: Boolean,
val resetAsciiMode: Boolean,
val resetAsciiMode: Boolean?,
val labelTransform: LabelTransform,
val lock: Boolean,
val asciiKeyboard: String,
@ -140,7 +140,7 @@ data class TextKeyboard(
keyBorder = node["key_border"]?.int ?: -1,
columns = node["columns"]?.int ?: 30,
asciiMode = (node["ascii_mode"]?.int ?: 1) == 1,
resetAsciiMode = node["reset_ascii_mode"]?.boolean ?: true,
resetAsciiMode = node["reset_ascii_mode"]?.boolean,
labelTransform = node["label_transform"]?.enum<LabelTransform>() ?: LabelTransform.NONE,
lock = node["lock"]?.boolean ?: false,
asciiKeyboard = node["ascii_keyboard"]?.string ?: "",

View File

@ -122,7 +122,7 @@ class Keyboard(
/** Keyboard default ascii mode */
val asciiMode = selfConfig?.asciiMode ?: false
val resetAsciiMode = selfConfig?.resetAsciiMode ?: true
val resetAsciiMode = selfConfig?.resetAsciiMode ?: theme.generalStyle.resetASCIIMode
var lastAsciiMode: Boolean = asciiMode
val landscapeKeyboard: String? = selfConfig?.landscapeKeyboard

View File

@ -105,6 +105,13 @@ class KeyboardWindow :
}
private fun attachKeyboard(target: String) {
currentKeyboard?.let {
val mode = rime.run { statusCached }.isAsciiMode
Timber.d("Leaving $currentKeyboardId with ascii_mode $mode, switching to $target")
it.lastAsciiMode = mode
}
currentKeyboardId = target
lastKeyboardId = target