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

View File

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

View File

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

View File

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

View File

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