From 9518ffd347983a4e5e18cc5892b2f172a8d7fb70 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Sun, 6 Mar 2022 10:10:47 +0800 Subject: [PATCH] KeyHandler(Input) // Use KeyCode to handle symbol menu. - CharCode is not reliable at all. KeyCode is the most accurate. KeyCode doesn't give a phuque about the character sent through macOS keyboard layouts but only focuses on which physical key is pressed. --- Source/Modules/ControllerModules/KeyHandler.mm | 2 +- .../Modules/ControllerModules/KeyHandlerInput.swift | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Source/Modules/ControllerModules/KeyHandler.mm b/Source/Modules/ControllerModules/KeyHandler.mm index 869d5560..759f9541 100644 --- a/Source/Modules/ControllerModules/KeyHandler.mm +++ b/Source/Modules/ControllerModules/KeyHandler.mm @@ -532,7 +532,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; } // MARK: Punctuation list - if ([input isSymbolMenuKey]) { + if ([input isSymbolMenuPhysicalKey] && ![input isShiftHold]) { // 得在這裡先 commit buffer,不然會導致「在摁 ESC 離開符號選單時會重複輸入上一次的組字區的內容」的不當行為。 // 於是這裡用「模擬一次 Enter 鍵的操作」使其代為執行這個 commit buffer 的動作。 diff --git a/Source/Modules/ControllerModules/KeyHandlerInput.swift b/Source/Modules/ControllerModules/KeyHandlerInput.swift index 04c0f6fb..7ab70873 100644 --- a/Source/Modules/ControllerModules/KeyHandlerInput.swift +++ b/Source/Modules/ControllerModules/KeyHandlerInput.swift @@ -41,11 +41,13 @@ import Cocoa case leftShift = 56 case rightShift = 60 case capsLock = 57 + case symbolMenuPhysicalKey = 50 } // CharCodes: https://theasciicode.com.ar/ascii-control-characters/horizontal-tab-ascii-code-9.html -enum CharCode: UInt16 { - case symbolMenuKey_ABC = 96 +enum CharCode: UInt/*16*/ { + case yajuusenpai = 1145141919810893 + // - CharCode is not reliable at all. KeyCode is the most accurate. KeyCode doesn't give a phuque about the character sent through macOS keyboard layouts but only focuses on which physical key is pressed. } class KeyHandlerInput: NSObject { @@ -231,9 +233,10 @@ class KeyHandlerInput: NSObject { KeyCode(rawValue: keyCode) == verticalModeOnlyChooseCandidateKey } - @objc var isSymbolMenuKey: Bool { - // 這裡用 CharCode 更合適,不然就無法輸入波浪鍵了。 - CharCode(rawValue: charCode) == CharCode.symbolMenuKey_ABC + @objc var isSymbolMenuPhysicalKey: Bool { + // 這裡必須用 KeyCode,這樣才不會受隨 macOS 版本更動的 Apple 動態注音鍵盤排列內容的影響。 + // 只是必須得與 ![input isShift] 搭配使用才可以(也就是僅判定 Shift 沒被摁下的情形)。 + KeyCode(rawValue: keyCode) == KeyCode.symbolMenuPhysicalKey } }