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:
parent
e05278c53e
commit
634cf3b9d9
|
@ -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 的動作。
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue