From ae5237e0ff4f39cb5ad0ba1d8af4ac9e011a815f Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Sun, 13 Mar 2022 15:07:04 +0800 Subject: [PATCH] KeyHandler(Input) // Revised conditioning of letter inputs. - This is to fix an issue of mishandling letter input condition. --- Source/Modules/ControllerModules/KeyHandler.mm | 4 ++-- Source/Modules/ControllerModules/KeyHandlerInput.swift | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Source/Modules/ControllerModules/KeyHandler.mm b/Source/Modules/ControllerModules/KeyHandler.mm index 0e6e8cb2..bc72647d 100644 --- a/Source/Modules/ControllerModules/KeyHandler.mm +++ b/Source/Modules/ControllerModules/KeyHandler.mm @@ -585,7 +585,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; // Lukhnos 這裡的處理反而會使得 Apple 倚天注音動態鍵盤佈局「敲不了半形大寫英文」的缺點曝露無疑,所以注釋掉。 // 至於他試圖用這種處理來解決的上游 UPR293 的問題,其實針對詞庫檔案的排序做點手腳就可以解決。威注音本來也就是這麼做的。 - if (/*[state isKindOfClass:[InputStateNotEmpty class]] && */(char) charCode >= 'A' && (char) charCode <= 'Z') { + if (/*[state isKindOfClass:[InputStateNotEmpty class]] && */[input isUpperCaseASCIILetterKey]) { std::string letter = std::string("_letter_") + std::string(1, (char) charCode); if ([self _handlePunctuation:letter state:state usingVerticalMode:input.useVerticalMode stateCallback:stateCallback errorCallback:errorCallback]) { return YES; @@ -1253,7 +1253,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; BOOL shouldAutoSelectCandidate = _bpmfReadingBuffer->isValidKey((char) charCode) || _languageModel->hasUnigramsForKey(customPunctuation) || _languageModel->hasUnigramsForKey(punctuation); - if (!shouldAutoSelectCandidate && (char) charCode >= 'A' && (char) charCode <= 'Z') { + if (!shouldAutoSelectCandidate && [input isUpperCaseASCIILetterKey]) { std::string letter = std::string("_letter_") + std::string(1, (char) charCode); if (_languageModel->hasUnigramsForKey(letter)) { shouldAutoSelectCandidate = YES; diff --git a/Source/Modules/ControllerModules/KeyHandlerInput.swift b/Source/Modules/ControllerModules/KeyHandlerInput.swift index 7ab70873..f29097fa 100644 --- a/Source/Modules/ControllerModules/KeyHandlerInput.swift +++ b/Source/Modules/ControllerModules/KeyHandlerInput.swift @@ -233,6 +233,11 @@ class KeyHandlerInput: NSObject { KeyCode(rawValue: keyCode) == verticalModeOnlyChooseCandidateKey } + @objc var isUpperCaseASCIILetterKey: Bool { + // 這裡必須加上「flags == .shift」,否則會出現某些情況下輸入法「誤判當前鍵入的非 Shift 字符為大寫」的問題。 + self.charCode >= 65 && self.charCode <= 90 && flags == .shift + } + @objc var isSymbolMenuPhysicalKey: Bool { // 這裡必須用 KeyCode,這樣才不會受隨 macOS 版本更動的 Apple 動態注音鍵盤排列內容的影響。 // 只是必須得與 ![input isShift] 搭配使用才可以(也就是僅判定 Shift 沒被摁下的情形)。