From d9b6ef9a6e55fb3ec4b9ef1ac21c634ece73f44c Mon Sep 17 00:00:00 2001 From: LeanBitLab Date: Mon, 16 Nov 2026 11:54:26 +0530 Subject: [PATCH] fix(cjk): reapply engine locale after session destroy or engine reload CjkInputManager cached the last locale sent to the engine and skipped setLocale when unchanged. destroySession() on finishing the input view (app switch) and engine reloads reset the engine to its default locale, so Japanese input fell back to Chinese Pinyin until the keyboard was restarted. Clear the cache on finish and track the engine instance. --- .../java/helium314/keyboard/latin/cjk/CjkInputManager.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/helium314/keyboard/latin/cjk/CjkInputManager.kt b/app/src/main/java/helium314/keyboard/latin/cjk/CjkInputManager.kt index 8a7a6c263..0e51a64ef 100644 --- a/app/src/main/java/helium314/keyboard/latin/cjk/CjkInputManager.kt +++ b/app/src/main/java/helium314/keyboard/latin/cjk/CjkInputManager.kt @@ -23,6 +23,8 @@ class CjkInputManager private constructor(private val context: Context) { private var uiListener: CjkUiListener? = null private var activeLocale: String? = null + // Engine instance that activeLocale was applied to; a reloaded engine starts from its default locale + private var localeEngine: ICjkEngine? = null var isComposing: Boolean = false internal set @@ -59,9 +61,10 @@ class CjkInputManager private constructor(private val context: Context) { } val lang = subtype?.locale?.language?.lowercase() ?: "zh" - if (activeLocale != lang) { + if (activeLocale != lang || localeEngine !== engine) { engine.setLocale(lang) activeLocale = lang + localeEngine = engine } val keysym = KeycodeTranslator.toKeysym(event) @@ -186,6 +189,8 @@ class CjkInputManager private constructor(private val context: Context) { } uiListener?.onSetCandidateStripVisibility(false) CjkPluginLoader.getEngine(context)?.destroySession() + // destroySession may reset the engine to its default locale (zh), so force setLocale on the next key + activeLocale = null } companion object {