InputHandler // Remove errorCallback().

This commit is contained in:
ShikiSuen 2022-10-14 13:31:52 +08:00
parent 581122720d
commit 0a0f02861b
8 changed files with 103 additions and 176 deletions

View File

@ -171,11 +171,7 @@ func handleInputText(_ inputText: String?, key keyCode: Int, modifiers flags: In
或者 InputHandler 內: 或者 InputHandler 內:
```swift ```swift
extension InputHandler { extension InputHandler {
func handle( func handle(input: InputSignalProtocol) -> Bool {
input: InputHandler,
state: InputState,
errorCallback: @escaping (String) -> Void
) -> Bool {
let charCode: UniChar = input.charCode let charCode: UniChar = input.charCode
... ...
} }
@ -242,7 +238,7 @@ if composeReading { // 符合按鍵組合條件
// 向語言模型詢問是否有對應的記錄 // 向語言模型詢問是否有對應的記錄
if !ifLangModelHasUnigrams(forKey: reading) { // 如果沒有的話 if !ifLangModelHasUnigrams(forKey: reading) { // 如果沒有的話
vCLog("B49C0979語彙庫內無「\(reading)」的匹配記錄。") vCLog("B49C0979語彙庫內無「\(reading)」的匹配記錄。")
errorCallback("114514") // 向狀態管理引擎回呼一個錯誤狀態 delegate.callError("114514") // 向狀態管理引擎回呼一個錯誤狀態
_composer.clear() // 清空注拼槽的內容 _composer.clear() // 清空注拼槽的內容
// 根據「天權星引擎 (威注音) 或 Gramambular (小麥) 的組字器是否為空」來判定回呼哪一種狀態 // 根據「天權星引擎 (威注音) 或 Gramambular (小麥) 的組字器是否為空」來判定回呼哪一種狀態
delegate.switchState( delegate.switchState(

View File

@ -37,6 +37,7 @@ public protocol InputHandlerDelegate {
var selectionKeys: String { get } var selectionKeys: String { get }
var state: IMEStateProtocol { get set } var state: IMEStateProtocol { get set }
var clientBundleIdentifier: String { get } var clientBundleIdentifier: String { get }
func callError(_ logMessage: String)
func switchState(_ newState: IMEStateProtocol) func switchState(_ newState: IMEStateProtocol)
func candidateController() -> CtlCandidateProtocol func candidateController() -> CtlCandidateProtocol
func candidateSelectionCalledByInputHandler(at index: Int) func candidateSelectionCalledByInputHandler(at index: Int)

View File

@ -17,17 +17,9 @@ extension InputHandler {
/// ///
/// - Parameters: /// - Parameters:
/// - input: /// - input:
/// - errorCallback:
/// - Returns: IMK /// - Returns: IMK
func handleCandidate( func handleCandidate(input: InputSignalProtocol) -> Bool {
input: InputSignalProtocol, guard let delegate = delegate else { return false }
errorCallback: @escaping (String) -> Void
) -> Bool {
guard let delegate = delegate else {
errorCallback("06661F6E")
return true
}
var ctlCandidate = delegate.candidateController() var ctlCandidate = delegate.candidateController()
let state = delegate.state let state = delegate.state
@ -79,7 +71,7 @@ extension InputHandler {
? ctlCandidate.highlightPreviousCandidate() ? ctlCandidate.highlightPreviousCandidate()
: ctlCandidate.highlightNextCandidate()) : ctlCandidate.highlightNextCandidate())
if !updated { if !updated {
errorCallback("9B691919") delegate.callError("9B691919")
} }
return true return true
} }
@ -96,7 +88,7 @@ extension InputHandler {
? ctlCandidate.showNextLine() ? ctlCandidate.showNextLine()
: ctlCandidate.highlightNextCandidate()) : ctlCandidate.highlightNextCandidate())
if !updated { if !updated {
errorCallback("A11C781F") delegate.callError("A11C781F")
} }
return true return true
} }
@ -106,7 +98,7 @@ extension InputHandler {
if input.isPageDown { if input.isPageDown {
let updated: Bool = ctlCandidate.showNextPage() let updated: Bool = ctlCandidate.showNextPage()
if !updated { if !updated {
errorCallback("9B691919") delegate.callError("9B691919")
} }
return true return true
} }
@ -116,7 +108,7 @@ extension InputHandler {
if input.isPageUp { if input.isPageUp {
let updated: Bool = ctlCandidate.showPreviousPage() let updated: Bool = ctlCandidate.showPreviousPage()
if !updated { if !updated {
errorCallback("9569955D") delegate.callError("9569955D")
} }
return true return true
} }
@ -127,11 +119,11 @@ extension InputHandler {
switch ctlCandidate.currentLayout { switch ctlCandidate.currentLayout {
case .horizontal: case .horizontal:
if !ctlCandidate.highlightPreviousCandidate() { if !ctlCandidate.highlightPreviousCandidate() {
errorCallback("1145148D") delegate.callError("1145148D")
} }
case .vertical: case .vertical:
if !ctlCandidate.showPreviousLine() { if !ctlCandidate.showPreviousLine() {
errorCallback("1919810D") delegate.callError("1919810D")
} }
@unknown default: @unknown default:
break break
@ -145,11 +137,11 @@ extension InputHandler {
switch ctlCandidate.currentLayout { switch ctlCandidate.currentLayout {
case .horizontal: case .horizontal:
if !ctlCandidate.highlightNextCandidate() { if !ctlCandidate.highlightNextCandidate() {
errorCallback("9B65138D") delegate.callError("9B65138D")
} }
case .vertical: case .vertical:
if !ctlCandidate.showNextLine() { if !ctlCandidate.showNextLine() {
errorCallback("9244908D") delegate.callError("9244908D")
} }
@unknown default: @unknown default:
break break
@ -163,11 +155,11 @@ extension InputHandler {
switch ctlCandidate.currentLayout { switch ctlCandidate.currentLayout {
case .horizontal: case .horizontal:
if !ctlCandidate.showPreviousLine() { if !ctlCandidate.showPreviousLine() {
errorCallback("9B614524") delegate.callError("9B614524")
} }
case .vertical: case .vertical:
if !ctlCandidate.highlightPreviousCandidate() { if !ctlCandidate.highlightPreviousCandidate() {
errorCallback("ASD9908D") delegate.callError("ASD9908D")
} }
@unknown default: @unknown default:
break break
@ -181,12 +173,12 @@ extension InputHandler {
switch ctlCandidate.currentLayout { switch ctlCandidate.currentLayout {
case .horizontal: case .horizontal:
if !ctlCandidate.showNextLine() { if !ctlCandidate.showNextLine() {
errorCallback("92B990DD") delegate.callError("92B990DD")
break break
} }
case .vertical: case .vertical:
if !ctlCandidate.highlightNextCandidate() { if !ctlCandidate.highlightNextCandidate() {
errorCallback("6B99908D") delegate.callError("6B99908D")
} }
@unknown default: @unknown default:
break break
@ -198,7 +190,7 @@ extension InputHandler {
if input.isHome { if input.isHome {
if ctlCandidate.selectedCandidateIndex == 0 { if ctlCandidate.selectedCandidateIndex == 0 {
errorCallback("9B6EDE8D") delegate.callError("9B6EDE8D")
} else { } else {
ctlCandidate.selectedCandidateIndex = 0 ctlCandidate.selectedCandidateIndex = 0
} }
@ -213,7 +205,7 @@ extension InputHandler {
} else { // count > 0!isEmpty滿 } else { // count > 0!isEmpty滿
if input.isEnd { if input.isEnd {
if ctlCandidate.selectedCandidateIndex == state.candidates.count - 1 { if ctlCandidate.selectedCandidateIndex == state.candidates.count - 1 {
errorCallback("9B69AAAD") delegate.callError("9B69AAAD")
} else { } else {
ctlCandidate.selectedCandidateIndex = state.candidates.count - 1 ctlCandidate.selectedCandidateIndex = state.candidates.count - 1
} }
@ -286,7 +278,7 @@ extension InputHandler {
if candidateIndex != -114_514 { if candidateIndex != -114_514 {
delegate.candidateSelectionCalledByInputHandler(at: candidateIndex) delegate.candidateSelectionCalledByInputHandler(at: candidateIndex)
delegate.switchState(IMEState.ofAbortion()) delegate.switchState(IMEState.ofAbortion())
return handleInput(event: input, errorCallback: errorCallback) return handleInput(event: input)
} }
return true return true
} }
@ -298,12 +290,12 @@ extension InputHandler {
var updated = true var updated = true
updated = input.isShiftHold ? ctlCandidate.showPreviousLine() : ctlCandidate.showNextLine() updated = input.isShiftHold ? ctlCandidate.showPreviousLine() : ctlCandidate.showNextLine()
if !updated { if !updated {
errorCallback("66F3477B") delegate.callError("66F3477B")
} }
return true return true
} }
errorCallback("172A0F81") delegate.callError("172A0F81")
return true return true
} }
} }

View File

@ -15,12 +15,8 @@ extension InputHandler {
/// InputHandler.HandleInput() /// InputHandler.HandleInput()
/// - Parameters: /// - Parameters:
/// - input: /// - input:
/// - errorCallback:
/// - Returns: IMK /// - Returns: IMK
func handleComposition( func handleComposition(input: InputSignalProtocol) -> Bool? {
input: InputSignalProtocol,
errorCallback: @escaping (String) -> Void
) -> Bool? {
guard let delegate = delegate else { return nil } guard let delegate = delegate else { return nil }
// MARK: (Handle BPMF Keys) // MARK: (Handle BPMF Keys)
@ -54,7 +50,7 @@ extension InputHandler {
composer = theComposer composer = theComposer
// generateStateOfInputting()調 generateStateOfInputting() // generateStateOfInputting()調 generateStateOfInputting()
} else { } else {
errorCallback("4B0DD2D4語彙庫內無「\(temporaryReadingKey)」的匹配記錄,放棄覆寫游標身後的內容。") delegate.callError("4B0DD2D4語彙庫內無「\(temporaryReadingKey)」的匹配記錄,放棄覆寫游標身後的內容。")
return true return true
} }
} }
@ -86,7 +82,7 @@ extension InputHandler {
// //
if !currentLM.hasUnigramsFor(key: readingKey) { if !currentLM.hasUnigramsFor(key: readingKey) {
errorCallback("B49C0979語彙庫內無「\(readingKey)」的匹配記錄。") delegate.callError("B49C0979語彙庫內無「\(readingKey)」的匹配記錄。")
if prefs.keepReadingUponCompositionError { if prefs.keepReadingUponCompositionError {
composer.intonation.clear() // 調 composer.intonation.clear() // 調

View File

@ -18,17 +18,7 @@ extension InputHandler {
/// - Parameter event: IMK /// - Parameter event: IMK
/// - Returns: `true` IMK`false` /// - Returns: `true` IMK`false`
public func handleEvent(_ event: NSEvent) -> Bool { public func handleEvent(_ event: NSEvent) -> Bool {
imkCandidatesEventPreHandler(event: event) ?? doHandleInput(event) imkCandidatesEventPreHandler(event: event) ?? handleInput(event: event)
}
/// 調
/// result bool IMK
/// handleCandidate()
private func doHandleInput(_ event: NSEvent) -> Bool {
handleInput(event: event) { errorString in
vCLog(errorString)
IMEApp.buzz()
}
} }
/// IMK /// IMK
@ -79,7 +69,7 @@ extension InputHandler {
let eventArray = [event] let eventArray = [event]
guard let imkC = delegate.candidateController() as? CtlCandidateIMK else { return false } guard let imkC = delegate.candidateController() as? CtlCandidateIMK else { return false }
if event.isEsc || event.isBackSpace || event.isDelete || (event.isShiftHold && !event.isSpace) { if event.isEsc || event.isBackSpace || event.isDelete || (event.isShiftHold && !event.isSpace) {
return doHandleInput(event) return handleInput(event: event)
} else if event.isSymbolMenuPhysicalKey { } else if event.isSymbolMenuPhysicalKey {
// //
switch imkC.currentLayout { switch imkC.currentLayout {
@ -108,7 +98,7 @@ extension InputHandler {
if let newEvent = newEvent { if let newEvent = newEvent {
if prefs.useSCPCTypingMode, delegate.state.type == .ofAssociates { if prefs.useSCPCTypingMode, delegate.state.type == .ofAssociates {
// input.isShiftHold Self.handle() // input.isShiftHold Self.handle()
return event.isShiftHold ? true : doHandleInput(event) return event.isShiftHold ? true : handleInput(event: event)
} else { } else {
if #available(macOS 10.14, *) { if #available(macOS 10.14, *) {
imkC.handleKeyboardEvent(newEvent) imkC.handleKeyboardEvent(newEvent)
@ -121,7 +111,7 @@ extension InputHandler {
} }
if prefs.useSCPCTypingMode, !event.isReservedKey { if prefs.useSCPCTypingMode, !event.isReservedKey {
return doHandleInput(event) return handleInput(event: event)
} }
if delegate.state.type == .ofAssociates, if delegate.state.type == .ofAssociates,
@ -129,7 +119,7 @@ extension InputHandler {
!event.isCursorClockLeft, !event.isCursorClockRight, !event.isSpace, !event.isCursorClockLeft, !event.isCursorClockRight, !event.isSpace,
!event.isEnter || !prefs.alsoConfirmAssociatedCandidatesByEnter !event.isEnter || !prefs.alsoConfirmAssociatedCandidatesByEnter
{ {
return doHandleInput(event) return handleInput(event: event)
} }
imkC.interpretKeyEvents(eventArray) imkC.interpretKeyEvents(eventArray)
return true return true

View File

@ -20,12 +20,8 @@ extension InputHandler {
/// - Remark: inputHandler.handleEvent() IMKCandidates /// - Remark: inputHandler.handleEvent() IMKCandidates
/// - Parameters: /// - Parameters:
/// - input: /// - input:
/// - errorCallback:
/// - Returns: IMK /// - Returns: IMK
func handleInput( func handleInput(event input: InputSignalProtocol) -> Bool {
event input: InputSignalProtocol,
errorCallback: @escaping (String) -> Void
) -> Bool {
// inputTest // inputTest
// //
// delegate // delegate
@ -41,7 +37,7 @@ extension InputHandler {
if state.type == .ofEmpty || state.type == .ofDeactivated { if state.type == .ofEmpty || state.type == .ofDeactivated {
return false return false
} }
errorCallback("550BCF7B: InputHandler just refused an invalid input.") delegate.callError("550BCF7B: InputHandler just refused an invalid input.")
delegate.switchState(state) delegate.switchState(state)
return true return true
} }
@ -105,13 +101,13 @@ extension InputHandler {
// MARK: (Handle Candidates) // MARK: (Handle Candidates)
if [.ofCandidates, .ofSymbolTable].contains(state.type) { if [.ofCandidates, .ofSymbolTable].contains(state.type) {
return handleCandidate(input: input, errorCallback: errorCallback) return handleCandidate(input: input)
} }
// MARK: (Handle Associated Phrases) // MARK: (Handle Associated Phrases)
if state.type == .ofAssociates { if state.type == .ofAssociates {
if handleCandidate(input: input, errorCallback: errorCallback) { if handleCandidate(input: input) {
return true return true
} else { } else {
delegate.switchState(IMEState.ofEmpty()) delegate.switchState(IMEState.ofEmpty())
@ -121,18 +117,14 @@ extension InputHandler {
// MARK: 便使() (Handle Marking) // MARK: 便使() (Handle Marking)
if state.type == .ofMarking { if state.type == .ofMarking {
if handleMarkingState(input: input, errorCallback: errorCallback) { return true } if handleMarkingState(input: input) { return true }
state = state.convertedToInputting state = state.convertedToInputting
delegate.switchState(state) delegate.switchState(state)
} }
// MARK: (Handle BPMF Keys) // MARK: (Handle BPMF Keys)
if let compositionHandled = handleComposition( if let compositionHandled = handleComposition(input: input) { return compositionHandled }
input: input, errorCallback: errorCallback
) {
return compositionHandled
}
// MARK: (Calling candidate window using Up / Down or PageUp / PageDn.) // MARK: (Calling candidate window using Up / Down or PageUp / PageDn.)
@ -161,12 +153,12 @@ extension InputHandler {
} }
return true return true
} else if input.isShiftHold { // Tab Shift+Command+Space / } else if input.isShiftHold { // Tab Shift+Command+Space /
return handleInlineCandidateRotation(reverseOrder: input.isCommandHold, errorCallback: errorCallback) return handleInlineCandidateRotation(reverseOrder: input.isCommandHold)
} }
} }
let candidateState: IMEStateProtocol = generateStateOfCandidates() let candidateState: IMEStateProtocol = generateStateOfCandidates()
if candidateState.candidates.isEmpty { if candidateState.candidates.isEmpty {
errorCallback("3572F238") delegate.callError("3572F238")
} else { } else {
delegate.switchState(candidateState) delegate.switchState(candidateState)
} }
@ -179,38 +171,38 @@ extension InputHandler {
switch keyCodeType { switch keyCodeType {
case .kEscape: return handleEsc() case .kEscape: return handleEsc()
case .kTab: case .kTab:
return handleInlineCandidateRotation(reverseOrder: input.isShiftHold, errorCallback: errorCallback) 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
return handleHome(errorCallback: errorCallback) return handleHome()
} else if input.isRight { // Ctrl+PgRt or Shift+PgRt } else if input.isRight { // Ctrl+PgRt or Shift+PgRt
return handleEnd(errorCallback: errorCallback) return handleEnd()
} }
} }
if input.isCursorBackward { // Forward if input.isCursorBackward { // Forward
return handleBackward(input: input, errorCallback: errorCallback) return handleBackward(input: input)
} }
if input.isCursorForward { // Backward if input.isCursorForward { // Backward
return handleForward(input: input, errorCallback: errorCallback) 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, errorCallback: errorCallback) return handleInlineCandidateRotation(reverseOrder: false)
} }
if input.isCursorClockLeft { if input.isCursorClockLeft {
return handleInlineCandidateRotation(reverseOrder: true, errorCallback: errorCallback) return handleInlineCandidateRotation(reverseOrder: true)
} }
} }
return handleClockKey(errorCallback: errorCallback) return handleClockKey()
} }
case .kHome: return handleHome(errorCallback: errorCallback) case .kHome: return handleHome()
case .kEnd: return handleEnd(errorCallback: errorCallback) case .kEnd: return handleEnd()
case .kBackSpace: case .kBackSpace:
return handleBackSpace(input: input, errorCallback: errorCallback) return handleBackSpace(input: input)
case .kWindowsDelete: case .kWindowsDelete:
return handleDelete(input: input, errorCallback: errorCallback) return handleDelete(input: input)
case .kCarriageReturn, .kLineFeed: case .kCarriageReturn, .kLineFeed:
return (input.isCommandHold && input.isControlHold) return (input.isCommandHold && input.isControlHold)
? (input.isOptionHold ? (input.isOptionHold
@ -236,12 +228,12 @@ extension InputHandler {
delegate.switchState(inputting) delegate.switchState(inputting)
let candidateState = generateStateOfCandidates() let candidateState = generateStateOfCandidates()
if candidateState.candidates.isEmpty { if candidateState.candidates.isEmpty {
errorCallback("B5127D8A") delegate.callError("B5127D8A")
} else { } else {
delegate.switchState(candidateState) delegate.switchState(candidateState)
} }
} else { // } else { //
errorCallback("17446655") delegate.callError("17446655")
} }
return true return true
} }
@ -280,7 +272,7 @@ extension InputHandler {
let parser = currentKeyboardParser let parser = currentKeyboardParser
let arrCustomPunctuations: [String] = [punctuationNamePrefix, parser, input.text] let arrCustomPunctuations: [String] = [punctuationNamePrefix, parser, input.text]
let customPunctuation: String = arrCustomPunctuations.joined() let customPunctuation: String = arrCustomPunctuations.joined()
if handlePunctuation(customPunctuation, errorCallback: errorCallback) { if handlePunctuation(customPunctuation) {
return true return true
} }
@ -289,7 +281,7 @@ extension InputHandler {
let arrPunctuations: [String] = [punctuationNamePrefix, input.text] let arrPunctuations: [String] = [punctuationNamePrefix, input.text]
let punctuation: String = arrPunctuations.joined() let punctuation: String = arrPunctuations.joined()
if handlePunctuation(punctuation, errorCallback: errorCallback) { if handlePunctuation(punctuation) {
return true return true
} }
@ -322,7 +314,7 @@ extension InputHandler {
return true return true
default: // case 0 default: // case 0
let letter = "_letter_\(inputText)" let letter = "_letter_\(inputText)"
if handlePunctuation(letter, errorCallback: errorCallback) { if handlePunctuation(letter) {
return true return true
} }
} }
@ -336,9 +328,9 @@ extension InputHandler {
/// F1-F12 /// F1-F12
/// 便 /// 便
if state.hasComposition || !composer.isEmpty { if state.hasComposition || !composer.isEmpty {
errorCallback( delegate.callError(
"Blocked data: charCode: \(input.charCode), keyCode: \(input.keyCode)") "Blocked data: charCode: \(input.charCode), keyCode: \(input.keyCode)")
errorCallback("A9BFF20E") delegate.callError("A9BFF20E")
delegate.switchState(state) delegate.switchState(state)
return true return true
} }

View File

@ -83,7 +83,6 @@ extension InputHandler {
// MARK: - // MARK: -
/// ///
/// - Parameters:
/// - Returns: /// - Returns:
func generateStateOfCandidates() -> IMEStateProtocol { func generateStateOfCandidates() -> IMEStateProtocol {
IMEState.ofCandidates( IMEState.ofCandidates(
@ -117,12 +116,8 @@ extension InputHandler {
/// ///
/// - Parameters: /// - Parameters:
/// - input: /// - input:
/// - errorCallback:
/// - Returns: SessionCtl IMK /// - Returns: SessionCtl IMK
func handleMarkingState( func handleMarkingState(input: InputSignalProtocol) -> Bool {
input: InputSignalProtocol,
errorCallback: @escaping (String) -> Void
) -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
let state = delegate.state let state = delegate.state
@ -133,7 +128,7 @@ extension InputHandler {
// //
if input.isControlHold, input.isCommandHold, input.isEnter { if input.isControlHold, input.isCommandHold, input.isEnter {
errorCallback("1198E3E5") delegate.callError("1198E3E5")
return true return true
} }
@ -141,15 +136,15 @@ extension InputHandler {
if input.isEnter { if input.isEnter {
// //
if input.isShiftHold, input.isCommandHold, !state.isFilterable { if input.isShiftHold, input.isCommandHold, !state.isFilterable {
errorCallback("2EAC1F7A") delegate.callError("2EAC1F7A")
return true return true
} }
if !state.isMarkedLengthValid { if !state.isMarkedLengthValid {
errorCallback("9AAFAC00") delegate.callError("9AAFAC00")
return true return true
} }
if !delegate.performUserPhraseOperation(addToFilter: false) { if !delegate.performUserPhraseOperation(addToFilter: false) {
errorCallback("5B69CC8D") delegate.callError("5B69CC8D")
return true return true
} }
delegate.switchState(generateStateOfInputting()) delegate.switchState(generateStateOfInputting())
@ -159,11 +154,11 @@ extension InputHandler {
// BackSpace & Delete // BackSpace & Delete
if input.isBackSpace || input.isDelete { if input.isBackSpace || input.isDelete {
if !state.isFilterable { if !state.isFilterable {
errorCallback("1F88B191") delegate.callError("1F88B191")
return true return true
} }
if !delegate.performUserPhraseOperation(addToFilter: true) { if !delegate.performUserPhraseOperation(addToFilter: true) {
errorCallback("68D3C6C8") delegate.callError("68D3C6C8")
return true return true
} }
delegate.switchState(generateStateOfInputting()) delegate.switchState(generateStateOfInputting())
@ -186,7 +181,7 @@ extension InputHandler {
marking.tooltipBackupForInputting = state.tooltipBackupForInputting marking.tooltipBackupForInputting = state.tooltipBackupForInputting
delegate.switchState(marking.markedRange.isEmpty ? marking.convertedToInputting : marking) delegate.switchState(marking.markedRange.isEmpty ? marking.convertedToInputting : marking)
} else { } else {
errorCallback("1149908D") delegate.callError("1149908D")
delegate.switchState(state) delegate.switchState(state)
} }
return true return true
@ -208,7 +203,7 @@ extension InputHandler {
marking.tooltipBackupForInputting = state.tooltipBackupForInputting marking.tooltipBackupForInputting = state.tooltipBackupForInputting
delegate.switchState(marking.markedRange.isEmpty ? marking.convertedToInputting : marking) delegate.switchState(marking.markedRange.isEmpty ? marking.convertedToInputting : marking)
} else { } else {
errorCallback("9B51408D") delegate.callError("9B51408D")
delegate.switchState(state) delegate.switchState(state)
} }
return true return true
@ -221,12 +216,8 @@ extension InputHandler {
/// ///
/// - Parameters: /// - Parameters:
/// - customPunctuation: /// - customPunctuation:
/// - errorCallback:
/// - Returns: SessionCtl IMK /// - Returns: SessionCtl IMK
func handlePunctuation( func handlePunctuation(_ customPunctuation: String) -> Bool {
_ customPunctuation: String,
errorCallback: @escaping (String) -> Void
) -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
let state = delegate.state let state = delegate.state
@ -236,7 +227,7 @@ extension InputHandler {
guard composer.isEmpty else { guard composer.isEmpty else {
// //
errorCallback("A9B69908D") delegate.callError("A9B69908D")
delegate.switchState(state) delegate.switchState(state)
return true return true
} }
@ -263,7 +254,7 @@ extension InputHandler {
} else { } else {
delegate.switchState(candidateState) delegate.switchState(candidateState)
} }
default: errorCallback("8DA4096E") default: delegate.callError("8DA4096E")
} }
return true return true
} }
@ -271,7 +262,6 @@ extension InputHandler {
// MARK: - Enter // MARK: - Enter
/// Enter /// Enter
/// - Parameters:
/// - Returns: SessionCtl IMK /// - Returns: SessionCtl IMK
func handleEnter() -> Bool { func handleEnter() -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
@ -286,7 +276,6 @@ extension InputHandler {
// MARK: - Command+Enter // MARK: - Command+Enter
/// Command+Enter /// Command+Enter
/// - Parameters:
/// - Returns: SessionCtl IMK /// - Returns: SessionCtl IMK
func handleCtrlCommandEnter() -> Bool { func handleCtrlCommandEnter() -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
@ -311,7 +300,6 @@ extension InputHandler {
// MARK: - Command+Option+Enter Ruby // MARK: - Command+Option+Enter Ruby
/// Command+Option+Enter Ruby /// Command+Option+Enter Ruby
/// - Parameters:
/// - Returns: SessionCtl IMK /// - Returns: SessionCtl IMK
func handleCtrlOptionCommandEnter() -> Bool { func handleCtrlOptionCommandEnter() -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
@ -346,12 +334,8 @@ extension InputHandler {
/// BackSpace (macOS Delete) /// BackSpace (macOS Delete)
/// - Parameters: /// - Parameters:
/// - input: /// - input:
/// - errorCallback:
/// - Returns: SessionCtl IMK /// - Returns: SessionCtl IMK
func handleBackSpace( func handleBackSpace(input: InputSignalProtocol) -> Bool {
input: InputSignalProtocol,
errorCallback: @escaping (String) -> Void
) -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
let state = delegate.state let state = delegate.state
guard state.type == .ofInputting else { return false } guard state.type == .ofInputting else { return false }
@ -385,7 +369,7 @@ extension InputHandler {
compositor.dropKey(direction: .rear) compositor.dropKey(direction: .rear)
walk() walk()
} else { } else {
errorCallback("9D69908D") delegate.callError("9D69908D")
delegate.switchState(state) delegate.switchState(state)
return true return true
} }
@ -406,12 +390,8 @@ extension InputHandler {
/// PC Delete (macOS Fn+BackSpace) /// PC Delete (macOS Fn+BackSpace)
/// - Parameters: /// - Parameters:
/// - input: /// - input:
/// - errorCallback:
/// - Returns: SessionCtl IMK /// - Returns: SessionCtl IMK
func handleDelete( func handleDelete(input: InputSignalProtocol) -> Bool {
input: InputSignalProtocol,
errorCallback: @escaping (String) -> Void
) -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
let state = delegate.state let state = delegate.state
guard state.type == .ofInputting else { return false } guard state.type == .ofInputting else { return false }
@ -422,7 +402,7 @@ extension InputHandler {
} }
if compositor.cursor == compositor.length, composer.isEmpty { if compositor.cursor == compositor.length, composer.isEmpty {
errorCallback("9B69938D") delegate.callError("9B69938D")
delegate.switchState(state) delegate.switchState(state)
return true return true
} }
@ -447,17 +427,13 @@ extension InputHandler {
// MARK: - 90 // MARK: - 90
/// 90 /// 90
/// - Parameters:
/// - errorCallback:
/// - Returns: SessionCtl IMK /// - Returns: SessionCtl IMK
func handleClockKey( func handleClockKey() -> Bool {
errorCallback: @escaping (String) -> Void
) -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
let state = delegate.state let state = delegate.state
guard state.type == .ofInputting else { return false } guard state.type == .ofInputting else { return false }
if !composer.isEmpty { if !composer.isEmpty {
errorCallback("9B6F908D") delegate.callError("9B6F908D")
} }
delegate.switchState(state) delegate.switchState(state)
return true return true
@ -466,18 +442,14 @@ extension InputHandler {
// MARK: - Home // MARK: - Home
/// Home /// Home
/// - Parameters:
/// - errorCallback:
/// - Returns: SessionCtl IMK /// - Returns: SessionCtl IMK
func handleHome( func handleHome() -> Bool {
errorCallback: @escaping (String) -> Void
) -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
let state = delegate.state let state = delegate.state
guard state.type == .ofInputting else { return false } guard state.type == .ofInputting else { return false }
if !composer.isEmpty { if !composer.isEmpty {
errorCallback("ABC44080") delegate.callError("ABC44080")
delegate.switchState(state) delegate.switchState(state)
return true return true
} }
@ -486,7 +458,7 @@ extension InputHandler {
compositor.cursor = 0 compositor.cursor = 0
delegate.switchState(generateStateOfInputting()) delegate.switchState(generateStateOfInputting())
} else { } else {
errorCallback("66D97F90") delegate.callError("66D97F90")
delegate.switchState(state) delegate.switchState(state)
} }
@ -496,18 +468,14 @@ extension InputHandler {
// MARK: - End // MARK: - End
/// End /// End
/// - Parameters:
/// - errorCallback:
/// - Returns: SessionCtl IMK /// - Returns: SessionCtl IMK
func handleEnd( func handleEnd() -> Bool {
errorCallback: @escaping (String) -> Void
) -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
let state = delegate.state let state = delegate.state
guard state.type == .ofInputting else { return false } guard state.type == .ofInputting else { return false }
if !composer.isEmpty { if !composer.isEmpty {
errorCallback("9B69908D") delegate.callError("9B69908D")
delegate.switchState(state) delegate.switchState(state)
return true return true
} }
@ -516,7 +484,7 @@ extension InputHandler {
compositor.cursor = compositor.length compositor.cursor = compositor.length
delegate.switchState(generateStateOfInputting()) delegate.switchState(generateStateOfInputting())
} else { } else {
errorCallback("9B69908E") delegate.callError("9B69908E")
delegate.switchState(state) delegate.switchState(state)
} }
@ -526,7 +494,6 @@ extension InputHandler {
// MARK: - Esc // MARK: - Esc
/// Esc /// Esc
/// - Parameters:
/// - Returns: SessionCtl IMK /// - Returns: SessionCtl IMK
func handleEsc() -> Bool { func handleEsc() -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
@ -555,18 +522,14 @@ extension InputHandler {
/// ///
/// - Parameters: /// - Parameters:
/// - input: /// - input:
/// - errorCallback:
/// - Returns: SessionCtl IMK /// - Returns: SessionCtl IMK
func handleForward( func handleForward(input: InputSignalProtocol) -> Bool {
input: InputSignalProtocol,
errorCallback: @escaping (String) -> Void
) -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
let state = delegate.state let state = delegate.state
guard state.type == .ofInputting else { return false } guard state.type == .ofInputting else { return false }
if !composer.isEmpty { if !composer.isEmpty {
errorCallback("B3BA5257") delegate.callError("B3BA5257")
delegate.switchState(state) delegate.switchState(state)
return true return true
} }
@ -587,16 +550,16 @@ extension InputHandler {
marking.tooltipBackupForInputting = state.tooltip marking.tooltipBackupForInputting = state.tooltip
delegate.switchState(marking) delegate.switchState(marking)
} else { } else {
errorCallback("BB7F6DB9") delegate.callError("BB7F6DB9")
delegate.switchState(state) delegate.switchState(state)
} }
} else if input.isOptionHold { } else if input.isOptionHold {
if input.isControlHold { if input.isControlHold {
return handleEnd(errorCallback: errorCallback) return handleEnd()
} }
// //
if !compositor.jumpCursorBySpan(to: .front) { if !compositor.jumpCursorBySpan(to: .front) {
errorCallback("33C3B580") delegate.callError("33C3B580")
delegate.switchState(state) delegate.switchState(state)
return true return true
} }
@ -609,7 +572,7 @@ extension InputHandler {
} }
delegate.switchState(generateStateOfInputting()) delegate.switchState(generateStateOfInputting())
} else { } else {
errorCallback("A96AAD58") delegate.callError("A96AAD58")
delegate.switchState(state) delegate.switchState(state)
} }
} }
@ -622,18 +585,14 @@ extension InputHandler {
/// ///
/// - Parameters: /// - Parameters:
/// - input: /// - input:
/// - errorCallback:
/// - Returns: SessionCtl IMK /// - Returns: SessionCtl IMK
func handleBackward( func handleBackward(input: InputSignalProtocol) -> Bool {
input: InputSignalProtocol,
errorCallback: @escaping (String) -> Void
) -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
let state = delegate.state let state = delegate.state
guard state.type == .ofInputting else { return false } guard state.type == .ofInputting else { return false }
if !composer.isEmpty { if !composer.isEmpty {
errorCallback("6ED95318") delegate.callError("6ED95318")
delegate.switchState(state) delegate.switchState(state)
return true return true
} }
@ -654,16 +613,16 @@ extension InputHandler {
marking.tooltipBackupForInputting = state.tooltip marking.tooltipBackupForInputting = state.tooltip
delegate.switchState(marking) delegate.switchState(marking)
} else { } else {
errorCallback("D326DEA3") delegate.callError("D326DEA3")
delegate.switchState(state) delegate.switchState(state)
} }
} else if input.isOptionHold { } else if input.isOptionHold {
if input.isControlHold { if input.isControlHold {
return handleHome(errorCallback: errorCallback) return handleHome()
} }
// //
if !compositor.jumpCursorBySpan(to: .rear) { if !compositor.jumpCursorBySpan(to: .rear) {
errorCallback("8D50DD9E") delegate.callError("8D50DD9E")
delegate.switchState(state) delegate.switchState(state)
return true return true
} }
@ -676,7 +635,7 @@ extension InputHandler {
} }
delegate.switchState(generateStateOfInputting()) delegate.switchState(generateStateOfInputting())
} else { } else {
errorCallback("7045E6F3") delegate.callError("7045E6F3")
delegate.switchState(state) delegate.switchState(state)
} }
} }
@ -689,18 +648,14 @@ extension InputHandler {
/// ///
/// - Parameters: /// - Parameters:
/// - reverseOrder: /// - reverseOrder:
/// - errorCallback:
/// - Returns: SessionCtl IMK /// - Returns: SessionCtl IMK
func handleInlineCandidateRotation( func handleInlineCandidateRotation(reverseOrder: Bool) -> Bool {
reverseOrder: Bool,
errorCallback: @escaping (String) -> Void
) -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
let state = delegate.state let state = delegate.state
if composer.isEmpty, compositor.isEmpty || compositor.walkedNodes.isEmpty { return false } if composer.isEmpty, compositor.isEmpty || compositor.walkedNodes.isEmpty { return false }
guard state.type == .ofInputting else { guard state.type == .ofInputting else {
guard state.type == .ofEmpty else { guard state.type == .ofEmpty else {
errorCallback("6044F081") delegate.callError("6044F081")
return true return true
} }
// 使 Tab // 使 Tab
@ -708,13 +663,13 @@ extension InputHandler {
} }
guard composer.isEmpty else { guard composer.isEmpty else {
errorCallback("A2DAF7BC") delegate.callError("A2DAF7BC")
return true return true
} }
let candidates = generateArrayOfCandidates(fixOrder: true) let candidates = generateArrayOfCandidates(fixOrder: true)
guard !candidates.isEmpty else { guard !candidates.isEmpty else {
errorCallback("3378A6DF") delegate.callError("3378A6DF")
return true return true
} }
@ -730,7 +685,7 @@ extension InputHandler {
} }
guard let currentNode = currentNode else { guard let currentNode = currentNode else {
errorCallback("F58DEA95") delegate.callError("F58DEA95")
return true return true
} }

View File

@ -22,6 +22,11 @@ extension SessionCtl: InputHandlerDelegate {
candidatePairSelected(at: index) candidatePairSelected(at: index)
} }
public func callError(_ logMessage: String) {
vCLog(logMessage)
IMEApp.buzz()
}
public func performUserPhraseOperation(addToFilter: Bool) -> Bool { public func performUserPhraseOperation(addToFilter: Bool) -> Bool {
guard state.type == .ofMarking else { return false } guard state.type == .ofMarking else { return false }
if !LMMgr.writeUserPhrase( if !LMMgr.writeUserPhrase(