From e039e8cadc2378f4c9013bc14d0bbe37e3591dad Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Thu, 1 Sep 2022 14:16:24 +0800 Subject: [PATCH] ctlIME // Use InputSignalProtocol. --- .../Modules/ControllerModules/ctlInputMethod_Common.swift | 7 ++----- Source/Modules/ControllerModules/ctlInputMethod_Core.swift | 5 ++--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Source/Modules/ControllerModules/ctlInputMethod_Common.swift b/Source/Modules/ControllerModules/ctlInputMethod_Common.swift index 4659e0f6..626d9384 100644 --- a/Source/Modules/ControllerModules/ctlInputMethod_Common.swift +++ b/Source/Modules/ControllerModules/ctlInputMethod_Common.swift @@ -51,19 +51,16 @@ extension ctlInputMethod { // 準備修飾鍵,用來判定要新增的詞彙是否需要賦以非常低的權重。 ctlInputMethod.areWeNerfing = event.modifierFlags.contains([.shift, .command]) - var input = InputSignal(event: event, isVerticalTyping: isVerticalTyping) - input.isASCIIModeInput = isASCIIMode - // 無法列印的訊號輸入,一概不作處理。 // 這個過程不能放在 KeyHandler 內,否則不會起作用。 - if !input.charCode.isPrintable { + if !event.charCode.isPrintable { return false } /// 將按鍵行為與當前輸入法狀態結合起來、交給按鍵調度模組來處理。 /// 再根據返回的 result bool 數值來告知 IMK「這個按鍵事件是被處理了還是被放行了」。 /// 這裡不用 keyHandler.handleCandidate() 是因為需要針對聯想詞輸入狀態做額外處理。 - let result = keyHandler.handle(input: input, state: state) { newState in + let result = keyHandler.handle(input: event, state: state) { newState in self.handle(state: newState) } errorCallback: { clsSFX.beep() diff --git a/Source/Modules/ControllerModules/ctlInputMethod_Core.swift b/Source/Modules/ControllerModules/ctlInputMethod_Core.swift index 7bcdb4f1..83c226d3 100644 --- a/Source/Modules/ControllerModules/ctlInputMethod_Core.swift +++ b/Source/Modules/ControllerModules/ctlInputMethod_Core.swift @@ -219,11 +219,10 @@ class ctlInputMethod: IMKInputController { proc: if let ctlCandidateCurrent = ctlInputMethod.ctlCandidateCurrent as? ctlCandidateIMK { guard ctlCandidateCurrent.visible else { break proc } let event: NSEvent = ctlCandidateIMK.replaceNumPadKeyCodes(target: event) ?? event - let input = InputSignal(event: event) // Shift+Enter 是個特殊情形,不提前攔截處理的話、會有垃圾參數傳給 delegate 的 keyHandler 從而崩潰。 // 所以這裡直接將 Shift Flags 清空。 - if input.isShiftHold, input.isEnter { + if event.isShiftHold, event.isEnter { guard let newEvent = NSEvent.keyEvent( with: event.type, @@ -246,7 +245,7 @@ class ctlInputMethod: IMKInputController { } // 聯想詞選字。 - if let newChar = ctlCandidateIMK.defaultIMKSelectionKey[event.keyCode], input.isShiftHold, + if let newChar = ctlCandidateIMK.defaultIMKSelectionKey[event.keyCode], event.isShiftHold, isAssociatedPhrasesState { let newEvent = NSEvent.keyEvent(