@@ -87,7 +87,7 @@ class KeyboardWindow(
8787
8888 override fun onCreateView (): View {
8989 keyboardView = context.frameLayout(R .id.keyboard_view)
90- attachKeyboard(evalKeyboard(rime. run { statusCached }.schemaId ))
90+ attachKeyboard(evalKeyboard(" .default " ))
9191 return keyboardView
9292 }
9393
@@ -97,6 +97,7 @@ class KeyboardWindow(
9797 keyboardView.removeView(it)
9898 it.keyboardActionListener = null
9999 }
100+ currentKeyboard?.lastAsciiMode = rime.run { statusCached }.isAsciiMode
100101 }
101102
102103 private fun selectKeyboardConfig (name : String ): TextKeyboard ? {
@@ -111,26 +112,33 @@ class KeyboardWindow(
111112 private fun attachKeyboard (target : String ) {
112113 currentKeyboardId = target
113114 lastKeyboardId = target
114- val newConfig = selectKeyboardConfig(target)
115- val newKeyboard =
116- (currentKeyboard ? : Keyboard (theme, newConfig)).also {
117- runBlocking {
118- _currentKeyboardHeight .emit(it.keyboardHeight)
119- }
120- if (it.isLock) lastLockKeyboardId = target
121- dispatchCapsState(it::setShifted)
122- val isAsciiMode = rime.run { statusCached }.isAsciiMode
123- if (isAsciiMode != it.asciiMode) {
124- service.postRimeJob { setRuntimeOption(" ascii_mode" , it.asciiMode) }
125- }
126- // TODO:为避免过量重构,这里暂时将 currentKeyboard 同步到 KeyboardSwitcher
127- KeyboardSwitcher .currentKeyboard = it
128- }
129- val newView =
130- currentKeyboardView ? : KeyboardView (context, theme, newKeyboard, popupComponent, service).also {
131- cachedKeyboards[target] = newKeyboard to it
115+
116+ val config = selectKeyboardConfig(target)
117+ val keyboard = currentKeyboard ? : Keyboard (theme, config)
118+ val view = currentKeyboardView ? : KeyboardView (context, theme, keyboard, popupComponent, service)
119+
120+ if (currentKeyboard == null ) {
121+ cachedKeyboards[target] = keyboard to view
122+ keyboard.lastAsciiMode = keyboard.asciiMode
123+ }
124+
125+ keyboard.also {
126+ runBlocking { _currentKeyboardHeight .emit(it.keyboardHeight) }
127+ if (it.isLock) lastLockKeyboardId = target
128+ dispatchCapsState(it::setShifted)
129+
130+ val currentMode = rime.run { statusCached }.isAsciiMode
131+ val targetMode = if (it.resetAsciiMode) it.asciiMode else it.lastAsciiMode
132+
133+ if (currentMode != targetMode) {
134+ service.postRimeJob { setRuntimeOption(" ascii_mode" , targetMode) }
132135 }
133- newView.let {
136+
137+ // TODO:为避免过量重构,这里暂时将 currentKeyboard 同步到 KeyboardSwitcher
138+ KeyboardSwitcher .currentKeyboard = it
139+ }
140+
141+ view.let {
134142 it.keyboardActionListener = keyboardActionListener
135143 keyboardView.apply { add(it, lParams(matchParent, matchParent)) }
136144 }
@@ -241,14 +249,9 @@ class KeyboardWindow(
241249 service.postRimeJob { setRuntimeOption(" ascii_mode" , true ) }
242250 }
243251 } else if (theme.generalStyle.resetASCIIMode) {
244- if (it.resetAsciiMode) {
245- if (isAsciiMode != it.asciiMode) {
246- service.postRimeJob { setRuntimeOption(" ascii_mode" , it.asciiMode) }
247- }
248- } else {
249- if (isAsciiMode) {
250- service.postRimeJob { setRuntimeOption(" ascii_mode" , false ) }
251- }
252+ val targetMode = if (it.resetAsciiMode) it.asciiMode else it.lastAsciiMode
253+ if (isAsciiMode != targetMode) {
254+ service.postRimeJob { setRuntimeOption(" ascii_mode" , targetMode) }
252255 }
253256 }
254257 }
@@ -279,7 +282,7 @@ class KeyboardWindow(
279282 }
280283
281284 override fun onRimeSchemaUpdated (schema : SchemaItem ) {
282- switchKeyboard(schema.id )
285+ switchKeyboard(" .default " )
283286 }
284287
285288 override fun onRimeOptionUpdated (value : RimeMessage .OptionMessage .Data ) {
0 commit comments