diff --git a/Source/Modules/ControllerModules/KeyHandler_HandleCandidate.swift b/Source/Modules/ControllerModules/KeyHandler_HandleCandidate.swift index 9f6e99e6..f369a266 100644 --- a/Source/Modules/ControllerModules/KeyHandler_HandleCandidate.swift +++ b/Source/Modules/ControllerModules/KeyHandler_HandleCandidate.swift @@ -307,13 +307,15 @@ extension KeyHandler { let punctuationNamePrefix: String = generatePunctuationNamePrefix(withKeyCondition: input) let parser = currentMandarinParser let arrCustomPunctuations: [String] = [ - punctuationNamePrefix, parser, String(format: "%c", CChar(charCode)), + punctuationNamePrefix, parser, String(format: "%c", charCode.isPrintableASCII ? CChar(charCode) : inputText), ] let customPunctuation: String = arrCustomPunctuations.joined(separator: "") /// 看看這個輸入是否是不需要修飾鍵的那種標點鍵輸入。 - let arrPunctuations: [String] = [punctuationNamePrefix, String(format: "%c", CChar(charCode))] + let arrPunctuations: [String] = [ + punctuationNamePrefix, String(format: "%c", charCode.isPrintableASCII ? CChar(charCode) : inputText), + ] let punctuation: String = arrPunctuations.joined(separator: "") var shouldAutoSelectCandidate: Bool = @@ -321,7 +323,9 @@ extension KeyHandler { || currentLM.hasUnigramsFor(key: punctuation) if !shouldAutoSelectCandidate, input.isUpperCaseASCIILetterKey { - let letter: String! = String(format: "%@%c", "_letter_", CChar(charCode)) + let letter: String! = String( + format: "%@%c", "_letter_", charCode.isPrintableASCII ? CChar(charCode) : inputText + ) if currentLM.hasUnigramsFor(key: letter) { shouldAutoSelectCandidate = true } } diff --git a/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift b/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift index a68d345d..6a53c36d 100644 --- a/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift +++ b/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift @@ -329,7 +329,7 @@ extension KeyHandler { let punctuationNamePrefix: String = generatePunctuationNamePrefix(withKeyCondition: input) let parser = currentMandarinParser let arrCustomPunctuations: [String] = [ - punctuationNamePrefix, parser, String(format: "%c", CChar(charCode)), + punctuationNamePrefix, parser, String(format: "%c", charCode.isPrintableASCII ? CChar(charCode) : inputText), ] let customPunctuation: String = arrCustomPunctuations.joined(separator: "") if handlePunctuation( @@ -344,7 +344,9 @@ extension KeyHandler { /// 如果仍無匹配結果的話,看看這個輸入是否是不需要修飾鍵的那種標點鍵輸入。 - let arrPunctuations: [String] = [punctuationNamePrefix, String(format: "%c", CChar(charCode))] + let arrPunctuations: [String] = [ + punctuationNamePrefix, String(format: "%c", charCode.isPrintableASCII ? CChar(charCode) : inputText), + ] let punctuation: String = arrPunctuations.joined(separator: "") if handlePunctuation( @@ -359,7 +361,7 @@ extension KeyHandler { // 這裡不使用小麥注音 2.2 版的組字區處理方式,而是直接由詞庫負責。 if input.isUpperCaseASCIILetterKey { - let letter: String! = String(format: "%@%c", "_letter_", CChar(charCode)) + let letter: String! = String(format: "%@%c", "_letter_", charCode.isPrintableASCII ? CChar(charCode) : inputText) if handlePunctuation( letter, state: state,