InputHandler // Simplify the arrow handling in handleInput().
This commit is contained in:
parent
272bfef227
commit
29b89518c0
|
@ -34,6 +34,7 @@ public protocol InputHandlerProtocol {
|
|||
|
||||
/// InputHandler 委任協定
|
||||
public protocol InputHandlerDelegate {
|
||||
var isVerticalTyping: Bool { get }
|
||||
var selectionKeys: String { get }
|
||||
var state: IMEStateProtocol { get set }
|
||||
var clientBundleIdentifier: String { get }
|
||||
|
|
|
@ -136,7 +136,7 @@ extension InputHandler {
|
|||
}
|
||||
return true
|
||||
} else if input.isShiftHold { // 臉書等網站會攔截 Tab 鍵,所以用 Shift+Command+Space 對候選字詞做正向/反向輪替。
|
||||
return handleInlineCandidateRotation(reverseOrder: input.isCommandHold)
|
||||
return rotateCandidate(reverseOrder: input.isCommandHold)
|
||||
}
|
||||
}
|
||||
// 開始決定是否切換至選字狀態。
|
||||
|
@ -150,16 +150,17 @@ extension InputHandler {
|
|||
if let keyCodeType = KeyCode(rawValue: input.keyCode) {
|
||||
switch keyCodeType {
|
||||
case .kEscape: return handleEsc()
|
||||
case .kTab: return handleInlineCandidateRotation(reverseOrder: input.isShiftHold)
|
||||
case .kTab: return rotateCandidate(reverseOrder: input.isShiftHold)
|
||||
case .kUpArrow, .kDownArrow, .kLeftArrow, .kRightArrow:
|
||||
if input.isCursorBackward { return handleBackward(input: input) } // Forward
|
||||
if input.isCursorForward { return handleForward(input: input) } // Backward
|
||||
if input.isCursorClockLeft || input.isCursorClockRight { // Clock keys
|
||||
if input.isOptionHold, state.type == .ofInputting {
|
||||
if input.isCursorClockRight { return handleInlineCandidateRotation(reverseOrder: false) }
|
||||
if input.isCursorClockLeft { return handleInlineCandidateRotation(reverseOrder: true) }
|
||||
}
|
||||
return handleClockKey()
|
||||
let rotation: Bool = input.isOptionHold && state.type == .ofInputting
|
||||
handleArrowKey: switch (keyCodeType, delegate.isVerticalTyping) {
|
||||
case (.kLeftArrow, false), (.kUpArrow, true): return handleBackward(input: input)
|
||||
case (.kRightArrow, false), (.kDownArrow, true): return handleForward(input: input)
|
||||
case (.kUpArrow, false), (.kLeftArrow, true):
|
||||
return rotation ? rotateCandidate(reverseOrder: true) : handleClockKey()
|
||||
case (.kDownArrow, false), (.kRightArrow, true):
|
||||
return rotation ? rotateCandidate(reverseOrder: false) : handleClockKey()
|
||||
default: break handleArrowKey // 該情況應該不會發生,因為上面都有處理過。
|
||||
}
|
||||
case .kHome: return handleHome()
|
||||
case .kEnd: return handleEnd()
|
||||
|
|
|
@ -640,7 +640,7 @@ extension InputHandler {
|
|||
/// - Parameters:
|
||||
/// - reverseOrder: 是否有控制輪替方向的修飾鍵輸入。
|
||||
/// - Returns: 將按鍵行為「是否有處理掉」藉由 SessionCtl 回報給 IMK。
|
||||
func handleInlineCandidateRotation(reverseOrder: Bool) -> Bool {
|
||||
func rotateCandidate(reverseOrder: Bool) -> Bool {
|
||||
guard let delegate = delegate else { return false }
|
||||
let state = delegate.state
|
||||
if composer.isEmpty, compositor.isEmpty || compositor.walkedNodes.isEmpty { return false }
|
||||
|
|
Loading…
Reference in New Issue