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.
This commit is contained in:
ShikiSuen 2022-03-06 10:10:47 +08:00
parent 7e16a05d54
commit 16620c6e28
2 changed files with 9 additions and 6 deletions

View File

@ -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 的動作。

View File

@ -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
}
}