Skip to content

Commit 5b78b88

Browse files
lzlv312WhiredPlanck
authored andcommitted
fix(keyboard): resolve schema name not refreshing when switching input methods after librime update
After the librime update, the schema name displayed on the space key would not refresh when switching input methods. The previous fix in PR #1810 directly set KeyAction.label to the schema name during initialization (when label was empty), using getSpaceKeySchemaName() as a fallback. However, when users switch input methods at runtime, Rime's status (statusCached.schemaName) changes, but KeyAction.label remains set to the old name and is no longer empty. As a result, getLabel() doesn't re-read getSpaceKeySchemaName(), leaving the interface displaying the old name until a keyboard rebuild or refresh is triggered by another operation. This change ensures that the space key's label isn't permanently fixed to a specific schema name during initialization, preventing the issue of "old values being cached". Now the schema name will correctly update when users switch input methods.
1 parent 2cf90f4 commit 5b78b88

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

app/src/main/java/com/osfans/trime/ime/keyboard/KeyAction.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,9 @@ class KeyAction(
110110
return adjustCase(shiftLabel, keyboard)
111111
}
112112
}
113-
val currentLabel = label.ifEmpty {
114-
// 特殊处理空格键:如果label为空且是空格键,尝试获取最新的schemaName
115-
getSpaceKeySchemaName().takeIf { code == KeyEvent.KEYCODE_SPACE } ?: label
116-
}
117-
return adjustCase(currentLabel, keyboard)
113+
// 仅在为空格键且 label 为空时才去查询 schema 名称,先检查键码以减少无谓计算
114+
val displayLabel = takeIf { code == KeyEvent.KEYCODE_SPACE && label.isEmpty() }?.let { getSpaceKeySchemaName() } ?: label
115+
return adjustCase(displayLabel, keyboard)
118116
}
119117

120118
fun getText(keyboard: Keyboard): String = if (text.isNotEmpty()) {
@@ -161,7 +159,7 @@ class KeyAction(
161159
if (label.isEmpty()) {
162160
label =
163161
when (code) {
164-
KeyEvent.KEYCODE_SPACE -> getSpaceKeySchemaName()
162+
KeyEvent.KEYCODE_SPACE -> ""
165163
KeyEvent.KEYCODE_UNKNOWN -> ""
166164
else -> Keycode.getDisplayLabel(code, modifier)
167165
}
@@ -191,7 +189,7 @@ class KeyAction(
191189
} else if (label.isEmpty()) {
192190
label =
193191
when (code) {
194-
KeyEvent.KEYCODE_SPACE -> getSpaceKeySchemaName()
192+
KeyEvent.KEYCODE_SPACE -> ""
195193
KeyEvent.KEYCODE_UNKNOWN -> ""
196194
else -> Keycode.getDisplayLabel(code, modifier)
197195
}

0 commit comments

Comments
 (0)