InputHandler // Simplifying aftermaths.
This commit is contained in:
parent
0a0f02861b
commit
e8e67a1f5f
|
@ -274,10 +274,8 @@ public class InputHandler: InputHandlerProtocol {
|
|||
/// 微軟新注音輸入法的游標後置風格也是不允許 nodeCrossing 的。
|
||||
var arrCandidates: [Megrez.Compositor.KeyValuePaired] = {
|
||||
switch prefs.useRearCursorMode {
|
||||
case false:
|
||||
return compositor.fetchCandidates(at: cursorForCandidate, filter: .endAt)
|
||||
case true:
|
||||
return compositor.fetchCandidates(at: cursorForCandidate, filter: .beginAt)
|
||||
case false: return compositor.fetchCandidates(at: cursorForCandidate, filter: .endAt)
|
||||
case true: return compositor.fetchCandidates(at: cursorForCandidate, filter: .beginAt)
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -349,36 +347,21 @@ public class InputHandler: InputHandlerProtocol {
|
|||
/// 給注拼槽指定注音排列或拼音輸入種類之後,將注拼槽內容清空。
|
||||
public func ensureKeyboardParser() {
|
||||
switch currentKeyboardParserType {
|
||||
case KeyboardParser.ofStandard:
|
||||
composer.ensureParser(arrange: .ofDachen)
|
||||
case KeyboardParser.ofDachen26:
|
||||
composer.ensureParser(arrange: .ofDachen26)
|
||||
case KeyboardParser.ofETen:
|
||||
composer.ensureParser(arrange: .ofETen)
|
||||
case KeyboardParser.ofHsu:
|
||||
composer.ensureParser(arrange: .ofHsu)
|
||||
case KeyboardParser.ofETen26:
|
||||
composer.ensureParser(arrange: .ofETen26)
|
||||
case KeyboardParser.ofIBM:
|
||||
composer.ensureParser(arrange: .ofIBM)
|
||||
case KeyboardParser.ofMiTAC:
|
||||
composer.ensureParser(arrange: .ofMiTAC)
|
||||
case KeyboardParser.ofFakeSeigyou:
|
||||
composer.ensureParser(arrange: .ofFakeSeigyou)
|
||||
case KeyboardParser.ofSeigyou:
|
||||
composer.ensureParser(arrange: .ofSeigyou)
|
||||
case KeyboardParser.ofStarlight:
|
||||
composer.ensureParser(arrange: .ofStarlight)
|
||||
case KeyboardParser.ofHanyuPinyin:
|
||||
composer.ensureParser(arrange: .ofHanyuPinyin)
|
||||
case KeyboardParser.ofSecondaryPinyin:
|
||||
composer.ensureParser(arrange: .ofSecondaryPinyin)
|
||||
case KeyboardParser.ofYalePinyin:
|
||||
composer.ensureParser(arrange: .ofYalePinyin)
|
||||
case KeyboardParser.ofHualuoPinyin:
|
||||
composer.ensureParser(arrange: .ofHualuoPinyin)
|
||||
case KeyboardParser.ofUniversalPinyin:
|
||||
composer.ensureParser(arrange: .ofUniversalPinyin)
|
||||
case KeyboardParser.ofStandard: composer.ensureParser(arrange: .ofDachen)
|
||||
case KeyboardParser.ofDachen26: composer.ensureParser(arrange: .ofDachen26)
|
||||
case KeyboardParser.ofETen: composer.ensureParser(arrange: .ofETen)
|
||||
case KeyboardParser.ofHsu: composer.ensureParser(arrange: .ofHsu)
|
||||
case KeyboardParser.ofETen26: composer.ensureParser(arrange: .ofETen26)
|
||||
case KeyboardParser.ofIBM: composer.ensureParser(arrange: .ofIBM)
|
||||
case KeyboardParser.ofMiTAC: composer.ensureParser(arrange: .ofMiTAC)
|
||||
case KeyboardParser.ofFakeSeigyou: composer.ensureParser(arrange: .ofFakeSeigyou)
|
||||
case KeyboardParser.ofSeigyou: composer.ensureParser(arrange: .ofSeigyou)
|
||||
case KeyboardParser.ofStarlight: composer.ensureParser(arrange: .ofStarlight)
|
||||
case KeyboardParser.ofHanyuPinyin: composer.ensureParser(arrange: .ofHanyuPinyin)
|
||||
case KeyboardParser.ofSecondaryPinyin: composer.ensureParser(arrange: .ofSecondaryPinyin)
|
||||
case KeyboardParser.ofYalePinyin: composer.ensureParser(arrange: .ofYalePinyin)
|
||||
case KeyboardParser.ofHualuoPinyin: composer.ensureParser(arrange: .ofHualuoPinyin)
|
||||
case KeyboardParser.ofUniversalPinyin: composer.ensureParser(arrange: .ofUniversalPinyin)
|
||||
}
|
||||
composer.clear()
|
||||
composer.phonabetCombinationCorrectionEnabled = prefs.autoCorrectReadingCombination
|
||||
|
|
|
@ -94,8 +94,7 @@ extension InputHandler {
|
|||
// 根據「組字器是否為空」來判定回呼哪一種狀態。
|
||||
switch compositor.isEmpty {
|
||||
case false: delegate.switchState(generateStateOfInputting())
|
||||
case true:
|
||||
delegate.switchState(IMEState.ofAbortion())
|
||||
case true: delegate.switchState(IMEState.ofAbortion())
|
||||
}
|
||||
return true // 向 IMK 報告說這個按鍵訊號已經被輸入法攔截處理了。
|
||||
}
|
||||
|
@ -134,10 +133,7 @@ extension InputHandler {
|
|||
if !prefs.associatedPhrasesEnabled {
|
||||
delegate.switchState(IMEState.ofEmpty())
|
||||
} else {
|
||||
let associatedPhrases =
|
||||
generateStateOfAssociates(
|
||||
withPair: .init(key: reading, value: text)
|
||||
)
|
||||
let associatedPhrases = generateStateOfAssociates(withPair: .init(key: reading, value: text))
|
||||
delegate.switchState(associatedPhrases.candidates.isEmpty ? IMEState.ofEmpty() : associatedPhrases)
|
||||
}
|
||||
default: break
|
||||
|
|
|
@ -170,8 +170,7 @@ 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 handleInlineCandidateRotation(reverseOrder: input.isShiftHold)
|
||||
case .kUpArrow, .kDownArrow, .kLeftArrow, .kRightArrow:
|
||||
if (input.isControlHold || input.isShiftHold) && (input.isOptionHold) {
|
||||
if input.isLeft { // Ctrl+PgLf / Shift+PgLf
|
||||
|
@ -180,30 +179,20 @@ extension InputHandler {
|
|||
return handleEnd()
|
||||
}
|
||||
}
|
||||
if input.isCursorBackward { // Forward
|
||||
return handleBackward(input: input)
|
||||
}
|
||||
if input.isCursorForward { // Backward
|
||||
return handleForward(input: input)
|
||||
}
|
||||
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)
|
||||
}
|
||||
if input.isCursorClockRight { return handleInlineCandidateRotation(reverseOrder: false) }
|
||||
if input.isCursorClockLeft { return handleInlineCandidateRotation(reverseOrder: true) }
|
||||
}
|
||||
return handleClockKey()
|
||||
}
|
||||
case .kHome: return handleHome()
|
||||
case .kEnd: return handleEnd()
|
||||
case .kBackSpace:
|
||||
return handleBackSpace(input: input)
|
||||
case .kWindowsDelete:
|
||||
return handleDelete(input: input)
|
||||
case .kCarriageReturn, .kLineFeed:
|
||||
case .kBackSpace: return handleBackSpace(input: input)
|
||||
case .kWindowsDelete: return handleDelete(input: input)
|
||||
case .kCarriageReturn, .kLineFeed: // Enter
|
||||
return (input.isCommandHold && input.isControlHold)
|
||||
? (input.isOptionHold
|
||||
? handleCtrlOptionCommandEnter()
|
||||
|
|
|
@ -50,6 +50,8 @@ extension InputHandler {
|
|||
}
|
||||
|
||||
/// 生成「正在輸入」狀態。
|
||||
/// - Parameter rawCursor: 原始游標。
|
||||
/// - Returns: 用以顯示的游標。
|
||||
func convertCursorForDisplay(_ rawCursor: Int) -> Int {
|
||||
var composedStringCursorIndex = 0
|
||||
var readingCursorIndex = 0
|
||||
|
@ -379,8 +381,7 @@ extension InputHandler {
|
|||
|
||||
switch composer.isEmpty && compositor.isEmpty {
|
||||
case false: delegate.switchState(generateStateOfInputting())
|
||||
case true:
|
||||
delegate.switchState(IMEState.ofAbortion())
|
||||
case true: delegate.switchState(IMEState.ofAbortion())
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
@ -418,8 +419,7 @@ extension InputHandler {
|
|||
// 這裡不用「count > 0」,因為該整數變數只要「!isEmpty」那就必定滿足這個條件。
|
||||
switch inputting.displayedText.isEmpty {
|
||||
case false: delegate.switchState(inputting)
|
||||
case true:
|
||||
delegate.switchState(IMEState.ofAbortion())
|
||||
case true: delegate.switchState(IMEState.ofAbortion())
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
@ -510,8 +510,7 @@ extension InputHandler {
|
|||
composer.clear()
|
||||
switch compositor.isEmpty {
|
||||
case false: delegate.switchState(generateStateOfInputting())
|
||||
case true:
|
||||
delegate.switchState(IMEState.ofAbortion())
|
||||
case true: delegate.switchState(IMEState.ofAbortion())
|
||||
}
|
||||
}
|
||||
return true
|
||||
|
|
|
@ -16,6 +16,7 @@ import Shared
|
|||
|
||||
extension SessionCtl {
|
||||
/// 接受所有鍵鼠事件為 NSEvent,讓輸入法判斷是否要處理、該怎樣處理。
|
||||
/// 然後再交給 InputHandler.handleEvent() 分診。
|
||||
/// - Parameters:
|
||||
/// - event: 裝置操作輸入事件,可能會是 nil。
|
||||
/// - sender: 呼叫了該函式的客體(無須使用)。
|
||||
|
|
Loading…
Reference in New Issue