diff --git a/Source/Modules/ControllerModules/InputSignal.swift b/Source/Modules/ControllerModules/InputSignal.swift index 3462f0e9..61aea850 100644 --- a/Source/Modules/ControllerModules/InputSignal.swift +++ b/Source/Modules/ControllerModules/InputSignal.swift @@ -137,12 +137,10 @@ struct InputSignal: CustomStringConvertible { private(set) var keyCode: UInt16 private var isFlagChanged: Bool private var flags: NSEvent.ModifierFlags - private var cursorForwardKey: KeyCode = .kNone - private var cursorBackwardKey: KeyCode = .kNone - private var extraChooseCandidateKey: KeyCode = .kNone - private var extraChooseCandidateKeyReverse: KeyCode = .kNone - private var absorbedArrowKey: KeyCode = .kNone - private var verticalTypingCandidateKey: KeyCode = .kNone + private var cursorForwardKey: KeyCode = .kNone // 12 o'clock + private var cursorBackwardKey: KeyCode = .kNone // 6 o'clock + private var cursorKeyClockRight: KeyCode = .kNone // 3 o'clock + private var cursorKeyClockLeft: KeyCode = .kNone // 9 o'clock private(set) var emacsKey: EmacsKey public init( @@ -191,14 +189,25 @@ struct InputSignal: CustomStringConvertible { mutating func defineArrowKeys() { cursorForwardKey = isTypingVertical ? .kDownArrow : .kRightArrow cursorBackwardKey = isTypingVertical ? .kUpArrow : .kLeftArrow - extraChooseCandidateKey = isTypingVertical ? .kLeftArrow : .kDownArrow - extraChooseCandidateKeyReverse = isTypingVertical ? .kRightArrow : .kUpArrow - absorbedArrowKey = isTypingVertical ? .kRightArrow : .kUpArrow - verticalTypingCandidateKey = isTypingVertical ? absorbedArrowKey : .kNone + cursorKeyClockLeft = isTypingVertical ? .kRightArrow : .kUpArrow + cursorKeyClockRight = isTypingVertical ? .kLeftArrow : .kDownArrow } var description: String { - "" + var result = "<[InputSignal] " + result += "inputText:\(String(describing: inputText)), " + result += "inputTextIgnoringModifiers:\(String(describing: inputTextIgnoringModifiers)), " + result += "charCode:\(charCode), " + result += "keyCode:\(keyCode), " + result += "flags:\(flags), " + result += "cursorForwardKey:\(cursorForwardKey), " + result += "cursorBackwardKey:\(cursorBackwardKey), " + result += "cursorKeyClockRight:\(cursorKeyClockRight), " + result += "cursorKeyClockLeft:\(cursorKeyClockLeft), " + result += "emacsKey:\(emacsKey), " + result += "isTypingVertical:\(isTypingVertical)" + result += ">" + return result } // 除了 ANSI charCode 以外,其餘一律過濾掉,免得純 Swift 版 KeyHandler 被餵屎。 @@ -248,10 +257,8 @@ struct InputSignal: CustomStringConvertible { var isDelete: Bool { KeyCode(rawValue: keyCode) == KeyCode.kWindowsDelete } var isCursorBackward: Bool { KeyCode(rawValue: keyCode) == cursorBackwardKey } var isCursorForward: Bool { KeyCode(rawValue: keyCode) == cursorForwardKey } - var isAbsorbedArrowKey: Bool { KeyCode(rawValue: keyCode) == absorbedArrowKey } - var isExtraChooseCandidateKey: Bool { KeyCode(rawValue: keyCode) == extraChooseCandidateKey } - var isExtraChooseCandidateKeyReverse: Bool { KeyCode(rawValue: keyCode) == extraChooseCandidateKeyReverse } - var isVerticalTypingCandidateKey: Bool { KeyCode(rawValue: keyCode) == verticalTypingCandidateKey } + var isCursorClockRight: Bool { KeyCode(rawValue: keyCode) == cursorKeyClockRight } + var isCursorClockLeft: Bool { KeyCode(rawValue: keyCode) == cursorKeyClockLeft } // 這裡必須加上「flags == .shift」,否則會出現某些情況下輸入法「誤判當前鍵入的非 Shift 字符為大寫」的問題。 var isUpperCaseASCIILetterKey: Bool { (65...90).contains(charCode) && flags == .shift } diff --git a/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift b/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift index 3b35f77f..0793cab1 100644 --- a/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift +++ b/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift @@ -78,8 +78,9 @@ extension KeyHandler { /// 這裡的處理原先是給威注音曾經有過的 Shift 切換英數模式來用的,但因為採 Chromium 核 /// 心的瀏覽器會讓 IMK 無法徹底攔截對 Shift 鍵的單擊行為、導致這個模式的使用體驗非常糟 /// 糕,故僅保留以 Caps Lock 驅動的英數模式。 - if input.isBackSpace || input.isEnter || input.isAbsorbedArrowKey || input.isExtraChooseCandidateKey - || input.isExtraChooseCandidateKeyReverse || input.isCursorForward || input.isCursorBackward + if input.isBackSpace || input.isEnter + || input.isCursorClockLeft || input.isCursorClockRight + || input.isCursorForward || input.isCursorBackward { // 略過對 BackSpace 的處理。 } else if input.isCapsLockOn { @@ -265,9 +266,8 @@ extension KeyHandler { // MARK: 用上下左右鍵呼叫選字窗 (Calling candidate window using Up / Down or PageUp / PageDn.) if let currentState = state as? InputState.NotEmpty, composer.isEmpty, !input.isOptionHold, - input.isExtraChooseCandidateKey || input.isExtraChooseCandidateKeyReverse || input.isSpace + input.isCursorClockLeft || input.isCursorClockRight || input.isSpace || input.isPageDown || input.isPageUp || (input.isTab && mgrPrefs.specifyShiftTabKeyBehavior) - || (input.isTypingVertical && (input.isVerticalTypingCandidateKey)) { if input.isSpace { /// 倘若沒有在偏好設定內將 Space 空格鍵設為選字窗呼叫用鍵的話……… @@ -353,22 +353,22 @@ extension KeyHandler { return handleEnd(state: state, stateCallback: stateCallback, errorCallback: errorCallback) } - // MARK: AbsorbedArrowKey + // MARK: Clock-Left & Clock-Right - if input.isAbsorbedArrowKey || input.isExtraChooseCandidateKey || input.isExtraChooseCandidateKeyReverse { + if input.isCursorClockLeft || input.isCursorClockRight { if input.isOptionHold, state is InputState.Inputting { - if input.isExtraChooseCandidateKey { + if input.isCursorClockRight { return handleInlineCandidateRotation( state: state, reverseModifier: false, stateCallback: stateCallback, errorCallback: errorCallback ) } - if input.isExtraChooseCandidateKeyReverse { + if input.isCursorClockLeft { return handleInlineCandidateRotation( state: state, reverseModifier: true, stateCallback: stateCallback, errorCallback: errorCallback ) } } - return handleAbsorbedArrowKey(state: state, stateCallback: stateCallback, errorCallback: errorCallback) + return handleClockKey(state: state, stateCallback: stateCallback, errorCallback: errorCallback) } // MARK: Backspace diff --git a/Source/Modules/ControllerModules/KeyHandler_States.swift b/Source/Modules/ControllerModules/KeyHandler_States.swift index 4bd97370..04bf65c0 100644 --- a/Source/Modules/ControllerModules/KeyHandler_States.swift +++ b/Source/Modules/ControllerModules/KeyHandler_States.swift @@ -509,7 +509,7 @@ extension KeyHandler { /// - stateCallback: 狀態回呼。 /// - errorCallback: 錯誤回呼。 /// - Returns: 將按鍵行為「是否有處理掉」藉由 ctlInputMethod 回報給 IMK。 - func handleAbsorbedArrowKey( + func handleClockKey( state: InputStateProtocol, stateCallback: @escaping (InputStateProtocol) -> Void, errorCallback: @escaping () -> Void