From 3cebed6a23867ffc0fce5c2758f07d74f856e1f7 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Sat, 26 Mar 2022 17:36:06 +0800 Subject: [PATCH] ctlIME // Propagate application of setKeyLayout(). --- Source/Modules/IMEModules/ctlInputMethod.swift | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Source/Modules/IMEModules/ctlInputMethod.swift b/Source/Modules/IMEModules/ctlInputMethod.swift index e8371f9e..aeb9e477 100644 --- a/Source/Modules/IMEModules/ctlInputMethod.swift +++ b/Source/Modules/IMEModules/ctlInputMethod.swift @@ -153,8 +153,8 @@ class ctlInputMethod: IMKInputController { override func activateServer(_ client: Any!) { UserDefaults.standard.synchronize() - // Override the keyboard layout. Use US if not set. - (client as? IMKTextInput)?.overrideKeyboard(withKeyboardNamed: mgrPrefs.basisKeyboardLayout) + // Override the keyboard layout to the basic one. + setKeyLayout(isfunctionKeyboardLayout: false) // reset the state currentCandidateClient = nil @@ -181,14 +181,17 @@ class ctlInputMethod: IMKInputController { newInputMode = InputMode.imeModeNULL } mgrLangModel.loadDataModel(newInputMode) + + // Remember to override the keyboard layout again -- treat this as an activate event. + setKeyLayout(isfunctionKeyboardLayout: false) + if keyHandler.inputMode != newInputMode { UserDefaults.standard.synchronize() - // Remember to override the keyboard layout again -- treat this as an activate event. - (client as? IMKTextInput)?.overrideKeyboard(withKeyboardNamed: mgrPrefs.basisKeyboardLayout) keyHandler.clear() keyHandler.inputMode = newInputMode self.handle(state: .Empty(), client: client) } + // 讓外界知道目前的簡繁體輸入模式。 ctlInputMethod.currentKeyHandler.inputMode = keyHandler.inputMode } @@ -208,7 +211,7 @@ class ctlInputMethod: IMKInputController { // 同時注意:必須在 event.type == .flagsChanged 結尾插入 return false, // 否則,每次處理這種判斷時都會觸發 NSInternalInconsistencyException。 if event.type == .flagsChanged { - (client as? IMKTextInput)?.overrideKeyboard(withKeyboardNamed: getKeyLayoutFlagsCondition(event) ? mgrPrefs.functionKeyboardLayout : mgrPrefs.basisKeyboardLayout) + setKeyLayout(isfunctionKeyboardLayout: getKeyLayoutFlagsCondition(event)) return false } }