From 827e7e4735ad55fff14fc09ed674077d4fb48172 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Wed, 21 Sep 2022 21:21:46 +0800 Subject: [PATCH] ctlIME // Simplify isASCIIMode toggling. --- Source/Modules/ctlInputMethod_Core.swift | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Source/Modules/ctlInputMethod_Core.swift b/Source/Modules/ctlInputMethod_Core.swift index 34df57b0..f6865e35 100644 --- a/Source/Modules/ctlInputMethod_Core.swift +++ b/Source/Modules/ctlInputMethod_Core.swift @@ -39,7 +39,13 @@ class ctlInputMethod: IMKInputController { // MARK: - /// 當前這個 ctlInputMethod 副本是否處於英數輸入模式。 - var isASCIIMode = false { didSet { setKeyLayout() } } + var isASCIIMode = false { + didSet { + resetKeyHandler() + setKeyLayout() + } + } + /// 按鍵調度模組的副本。 var keyHandler = KeyHandler(lm: LMMgr.currentLM(), uom: LMMgr.currentUOM(), pref: PrefMgr.shared) /// 用以記錄當前輸入法狀態的變數。 @@ -53,13 +59,6 @@ class ctlInputMethod: IMKInputController { /// - Remark: 警告:該工具必須為 Struct 且全專案只能有一個唯一初期化副本。否則會在動 CapsLock 的時候誤以為是在摁 Shift。 static var theShiftKeyDetector = ShiftKeyUpChecker(useLShift: PrefMgr.shared.togglingAlphanumericalModeWithLShift) - /// 切換當前 ctlInputMethod 副本的英數輸入模式開關。 - func toggleASCIIMode() -> Bool { - resetKeyHandler() - isASCIIMode.toggle() - return isASCIIMode - } - /// `handle(event:)` 會利用這個參數判定某次 Shift 按鍵是否用來切換中英文輸入。 var rencentKeyHandledByKeyHandlerEtc = false @@ -274,7 +273,7 @@ class ctlInputMethod: IMKInputController { if Self.theShiftKeyDetector.check(event), !PrefMgr.shared.disableShiftTogglingAlphanumericalMode { if !shouldUseShiftToggleHandle || (!rencentKeyHandledByKeyHandlerEtc && shouldUseShiftToggleHandle) { NotifierController.notify( - message: toggleASCIIMode() + message: isASCIIMode.toggled() ? NSLocalizedString("Alphanumerical Input Mode", comment: "") : NSLocalizedString("Chinese Input Mode", comment: "") )