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