diff --git a/Source/Modules/InputHandler_HandleComposition.swift b/Source/Modules/InputHandler_HandleComposition.swift index 7dea9033..3a139c27 100644 --- a/Source/Modules/InputHandler_HandleComposition.swift +++ b/Source/Modules/InputHandler_HandleComposition.swift @@ -17,6 +17,8 @@ extension InputHandler { /// - input: 輸入訊號。 /// - Returns: 告知 IMK「該按鍵是否已經被輸入法攔截處理」。 func handleComposition(input: InputSignalProtocol) -> Bool? { + // 不處理任何包含不可列印字元的訊號。 + guard !input.text.isEmpty, input.charCode.isPrintable else { return nil } if isCodePointInputMode { return handleCodePointComposition(input: input) } if prefs.cassetteEnabled { return handleCassetteComposition(input: input) } return handlePhonabetComposition(input: input) diff --git a/Source/Modules/InputHandler_HandleInput.swift b/Source/Modules/InputHandler_HandleInput.swift index 860e13fd..e0c88c74 100644 --- a/Source/Modules/InputHandler_HandleInput.swift +++ b/Source/Modules/InputHandler_HandleInput.swift @@ -23,10 +23,8 @@ extension InputHandler { /// - input: 輸入訊號。 /// - Returns: 告知 IMK「該按鍵是否已經被輸入法攔截處理」。 func handleInput(event input: InputSignalProtocol) -> Bool { - // 如果按鍵訊號內的 inputTest 是空的話,則忽略該按鍵輸入,因為很可能是功能修飾鍵。 - // 不處理任何包含不可列印字元的訊號。 // delegate 必須存在,否則不處理。 - guard !input.text.isEmpty, input.charCode.isPrintable, let delegate = delegate else { return false } + guard let delegate = delegate else { return false } let inputText: String = input.text var state: IMEStateProtocol { delegate.state } // 常數轉變數。 @@ -83,6 +81,12 @@ extension InputHandler { if [.ofCandidates, .ofSymbolTable].contains(state.type) { return handleCandidate(input: input) } + // MARK: 攔截部分無效按鍵。 + + // 如果按鍵訊號內的 inputTest 是空的話,則忽略該按鍵輸入,因為很可能是功能修飾鍵。 + // 不處理任何包含不可列印字元的訊號。 + guard !input.text.isEmpty, input.charCode.isPrintable else { return false } + // MARK: 處理聯想詞 (Handle Associated Phrases) if state.type == .ofAssociates {