diff --git a/Source/Modules/ControllerModules/KeyHandler_Core.swift b/Source/Modules/ControllerModules/KeyHandler_Core.swift index 531c2213..40b33e51 100644 --- a/Source/Modules/ControllerModules/KeyHandler_Core.swift +++ b/Source/Modules/ControllerModules/KeyHandler_Core.swift @@ -392,10 +392,10 @@ public class KeyHandler { /// 檢測某個傳入的按鍵訊號是否為聲調鍵。 /// - Parameter input: 傳入的按鍵訊號。 /// - Returns: 判斷結果:是否為聲調鍵。 - func isIntonationKey(_ input: InputSignal) -> Bool { + func isIntonationKey(_ input: InputSignalProtocol) -> Bool { var theComposer = composer // 複製一份用來做實驗。 theComposer.clear() // 清空各種槽的內容。 - theComposer.receiveKey(fromCharCode: input.charCode) + theComposer.receiveKey(fromString: input.text) return theComposer.hasToneMarker(withNothingElse: true) } @@ -417,7 +417,7 @@ public class KeyHandler { /// 生成標點符號索引鍵。 /// - Parameter input: 輸入的按鍵訊號。 /// - Returns: 生成的標點符號索引鍵。 - func generatePunctuationNamePrefix(withKeyCondition input: InputSignal) -> String { + func generatePunctuationNamePrefix(withKeyCondition input: InputSignalProtocol) -> String { if mgrPrefs.halfWidthPunctuationEnabled { return "_half_punctuation_" } diff --git a/Source/Modules/ControllerModules/KeyHandler_HandleCandidate.swift b/Source/Modules/ControllerModules/KeyHandler_HandleCandidate.swift index 895dc668..ff6b89ed 100644 --- a/Source/Modules/ControllerModules/KeyHandler_HandleCandidate.swift +++ b/Source/Modules/ControllerModules/KeyHandler_HandleCandidate.swift @@ -24,12 +24,10 @@ extension KeyHandler { /// - Returns: 告知 IMK「該按鍵是否已經被輸入法攔截處理」。 func handleCandidate( state: InputStateProtocol, - input: InputSignal, + input: InputSignalProtocol, stateCallback: @escaping (InputStateProtocol) -> Void, errorCallback: @escaping () -> Void ) -> Bool { - let inputText = input.inputText - let charCode: UniChar = input.charCode guard var ctlCandidateCurrent = delegate?.ctlCandidate() else { IME.prtDebugIntel("06661F6E") errorCallback() @@ -275,7 +273,7 @@ extension KeyHandler { var index: Int = NSNotFound let match: String = - (state is InputState.AssociatedPhrases) ? input.inputTextIgnoringModifiers ?? "" : inputText + (state is InputState.AssociatedPhrases) ? input.inputTextIgnoringModifiers ?? "" : input.text for j in 0.. Void, errorCallback: @escaping () -> Void ) -> Bool? { @@ -42,7 +42,7 @@ extension KeyHandler { prevReading.0.charComponents.forEach { theComposer.receiveKey(fromPhonabet: $0) } // 發現要覆寫的聲調與覆寫對象的聲調雷同的情況的話,直接跳過處理。 let oldIntonation: Tekkon.Phonabet = theComposer.intonation - theComposer.receiveKey(fromCharCode: input.charCode) + theComposer.receiveKey(fromString: input.text) if theComposer.intonation == oldIntonation, mgrPrefs.specifyIntonationKeyBehavior == 1 { break proc } theComposer.intonation.clear() // 檢查新的漢字字音是否在庫。 @@ -59,7 +59,7 @@ extension KeyHandler { } } - composer.receiveKey(fromCharCode: input.charCode) + composer.receiveKey(fromString: input.text) keyConsumedByReading = true // 沒有調號的話,只需要 updateClientComposingBuffer() 且終止處理(return true)即可。 diff --git a/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift b/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift index 43fd7e40..ebcb3ff4 100644 --- a/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift +++ b/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift @@ -24,16 +24,15 @@ extension KeyHandler { /// - errorCallback: 錯誤回呼。 /// - Returns: 告知 IMK「該按鍵是否已經被輸入法攔截處理」。 func handle( - input: InputSignal, + input: InputSignalProtocol, state: InputStateProtocol, stateCallback: @escaping (InputStateProtocol) -> Void, errorCallback: @escaping () -> Void ) -> Bool { // 如果按鍵訊號內的 inputTest 是空的話,則忽略該按鍵輸入,因為很可能是功能修飾鍵。 - guard !input.inputText.isEmpty else { return false } + guard !input.text.isEmpty else { return false } - let charCode: UniChar = input.charCode - let inputText: String = input.inputText + let inputText: String = input.text var state = state // 常數轉變數。 // 提前過濾掉一些不合規的按鍵訊號輸入,免得相關按鍵訊號被送給 Megrez 引發輸入法崩潰。 @@ -78,7 +77,7 @@ extension KeyHandler { /// 如果是 ASCII 當中的不可列印的字元的話,不使用「insertText:replacementRange:」。 /// 某些應用無法正常處理非 ASCII 字符的輸入。 - if charCode < 0x80, !charCode.isPrintableASCII { + if input.isASCII, !input.charCode.isPrintableASCII { return false } @@ -309,7 +308,7 @@ extension KeyHandler { if input.isMainAreaNumKey, input.isShiftHold, input.isOptionHold, !input.isControlHold, !input.isCommandHold { // NOTE: 將來棄用 macOS 10.11 El Capitan 支援的時候,把這裡由 CFStringTransform 改為 StringTransform: // https://developer.apple.com/documentation/foundation/stringtransform - guard let stringRAW = input.mapMainAreaNumKey[input.keyCode] else { return false } + guard let stringRAW = input.mainAreaNumKeyChar else { return false } let string = NSMutableString(string: stringRAW) CFStringTransform(string, nil, kCFStringTransformFullwidthHalfwidth, true) stateCallback( @@ -328,9 +327,7 @@ extension KeyHandler { let punctuationNamePrefix: String = generatePunctuationNamePrefix(withKeyCondition: input) let parser = currentMandarinParser - let arrCustomPunctuations: [String] = [ - punctuationNamePrefix, parser, String(format: "%c", charCode.isPrintableASCII ? CChar(charCode) : inputText), - ] + let arrCustomPunctuations: [String] = [punctuationNamePrefix, parser, input.text] let customPunctuation: String = arrCustomPunctuations.joined(separator: "") if handlePunctuation( customPunctuation, @@ -344,9 +341,7 @@ extension KeyHandler { /// 如果仍無匹配結果的話,看看這個輸入是否是不需要修飾鍵的那種標點鍵輸入。 - let arrPunctuations: [String] = [ - punctuationNamePrefix, String(format: "%c", charCode.isPrintableASCII ? CChar(charCode) : inputText), - ] + let arrPunctuations: [String] = [punctuationNamePrefix, input.text] let punctuation: String = arrPunctuations.joined(separator: "") if handlePunctuation( @@ -386,9 +381,7 @@ extension KeyHandler { stateCallback(InputState.Empty()) return true default: // 包括 case 0,直接塞給組字區。 - let letter: String! = String( - format: "%@%c", "_letter_", charCode.isPrintableASCII ? CChar(charCode) : inputText - ) + let letter = "_letter_\(inputText)" if handlePunctuation( letter, state: state, @@ -410,7 +403,7 @@ extension KeyHandler { /// 暫時只能先恢復這段,且補上偵錯彙報機制,方便今後排查故障。 if (state is InputState.NotEmpty) || !composer.isEmpty { IME.prtDebugIntel( - "Blocked data: charCode: \(charCode), keyCode: \(input.keyCode)") + "Blocked data: charCode: \(input.charCode), keyCode: \(input.keyCode)") IME.prtDebugIntel("A9BFF20E") errorCallback() stateCallback(state) diff --git a/Source/Modules/ControllerModules/KeyHandler_States.swift b/Source/Modules/ControllerModules/KeyHandler_States.swift index c8dbf982..a2763e77 100644 --- a/Source/Modules/ControllerModules/KeyHandler_States.swift +++ b/Source/Modules/ControllerModules/KeyHandler_States.swift @@ -170,7 +170,7 @@ extension KeyHandler { /// - Returns: 將按鍵行為「是否有處理掉」藉由 ctlInputMethod 回報給 IMK。 func handleMarkingState( _ state: InputState.Marking, - input: InputSignal, + input: InputSignalProtocol, stateCallback: @escaping (InputStateProtocol) -> Void, errorCallback: @escaping () -> Void ) -> Bool { @@ -416,7 +416,7 @@ extension KeyHandler { /// - Returns: 將按鍵行為「是否有處理掉」藉由 ctlInputMethod 回報給 IMK。 func handleBackSpace( state: InputStateProtocol, - input: InputSignal, + input: InputSignalProtocol, stateCallback: @escaping (InputStateProtocol) -> Void, errorCallback: @escaping () -> Void ) -> Bool { @@ -482,7 +482,7 @@ extension KeyHandler { /// - Returns: 將按鍵行為「是否有處理掉」藉由 ctlInputMethod 回報給 IMK。 func handleDelete( state: InputStateProtocol, - input: InputSignal, + input: InputSignalProtocol, stateCallback: @escaping (InputStateProtocol) -> Void, errorCallback: @escaping () -> Void ) -> Bool { @@ -652,7 +652,7 @@ extension KeyHandler { /// - Returns: 將按鍵行為「是否有處理掉」藉由 ctlInputMethod 回報給 IMK。 func handleForward( state: InputStateProtocol, - input: InputSignal, + input: InputSignalProtocol, stateCallback: @escaping (InputStateProtocol) -> Void, errorCallback: @escaping () -> Void ) -> Bool { @@ -726,7 +726,7 @@ extension KeyHandler { /// - Returns: 將按鍵行為「是否有處理掉」藉由 ctlInputMethod 回報給 IMK。 func handleBackward( state: InputStateProtocol, - input: InputSignal, + input: InputSignalProtocol, stateCallback: @escaping (InputStateProtocol) -> Void, errorCallback: @escaping () -> Void ) -> Bool {