InputHandler // Simplifying aftermaths.

This commit is contained in:
ShikiSuen 2022-10-14 13:45:02 +08:00
parent 0a0f02861b
commit e8e67a1f5f
5 changed files with 33 additions and 65 deletions

View File

@ -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

View File

@ -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

View File

@ -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()

View File

@ -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

View File

@ -16,6 +16,7 @@ import Shared
extension SessionCtl {
/// NSEvent
/// InputHandler.handleEvent()
/// - Parameters:
/// - event: nil
/// - sender: 使