InputHandler // Remove state parameter.

This commit is contained in:
ShikiSuen 2022-10-14 13:07:22 +08:00
parent 36a83f25a2
commit 581122720d
7 changed files with 63 additions and 127 deletions

View File

@ -40,7 +40,7 @@ public protocol InputHandlerDelegate {
func switchState(_ newState: IMEStateProtocol) func switchState(_ newState: IMEStateProtocol)
func candidateController() -> CtlCandidateProtocol func candidateController() -> CtlCandidateProtocol
func candidateSelectionCalledByInputHandler(at index: Int) func candidateSelectionCalledByInputHandler(at index: Int)
func performUserPhraseOperation(with state: IMEStateProtocol, addToFilter: Bool) func performUserPhraseOperation(addToFilter: Bool)
-> Bool -> Bool
} }

View File

@ -17,11 +17,9 @@ extension InputHandler {
/// ///
/// - Parameters: /// - Parameters:
/// - input: /// - input:
/// - state:
/// - errorCallback: /// - errorCallback:
/// - Returns: IMK /// - Returns: IMK
func handleCandidate( func handleCandidate(
state: IMEStateProtocol,
input: InputSignalProtocol, input: InputSignalProtocol,
errorCallback: @escaping (String) -> Void errorCallback: @escaping (String) -> Void
) -> Bool { ) -> Bool {
@ -31,6 +29,7 @@ extension InputHandler {
} }
var ctlCandidate = delegate.candidateController() var ctlCandidate = delegate.candidateController()
let state = delegate.state
// MARK: (Cancel Candidate) // MARK: (Cancel Candidate)
@ -287,9 +286,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( return handleInput(event: input, errorCallback: errorCallback)
event: input, state: IMEState.ofEmpty(), errorCallback: errorCallback
)
} }
return true return true
} }

View File

@ -126,7 +126,7 @@ extension InputHandler {
/// ///
if prefs.useSCPCTypingMode { if prefs.useSCPCTypingMode {
let candidateState: IMEStateProtocol = generateStateOfCandidates(state: inputting) let candidateState: IMEStateProtocol = generateStateOfCandidates()
switch candidateState.candidates.count { switch candidateState.candidates.count {
case 2...: delegate.switchState(candidateState) case 2...: delegate.switchState(candidateState)
case 1: case 1:

View File

@ -25,8 +25,7 @@ extension InputHandler {
/// result bool IMK /// result bool IMK
/// handleCandidate() /// handleCandidate()
private func doHandleInput(_ event: NSEvent) -> Bool { private func doHandleInput(_ event: NSEvent) -> Bool {
guard let delegate = delegate else { return false } handleInput(event: event) { errorString in
return handleInput(event: event, state: delegate.state) { errorString in
vCLog(errorString) vCLog(errorString)
IMEApp.buzz() IMEApp.buzz()
} }

View File

@ -20,12 +20,10 @@ extension InputHandler {
/// - Remark: inputHandler.handleEvent() IMKCandidates /// - Remark: inputHandler.handleEvent() IMKCandidates
/// - Parameters: /// - Parameters:
/// - input: /// - input:
/// - state:
/// - errorCallback: /// - errorCallback:
/// - Returns: IMK /// - Returns: IMK
func handleInput( func handleInput(
event input: InputSignalProtocol, event input: InputSignalProtocol,
state: IMEStateProtocol,
errorCallback: @escaping (String) -> Void errorCallback: @escaping (String) -> Void
) -> Bool { ) -> Bool {
// inputTest // inputTest
@ -34,7 +32,7 @@ extension InputHandler {
guard !input.text.isEmpty, input.charCode.isPrintable, let delegate = delegate else { return false } guard !input.text.isEmpty, input.charCode.isPrintable, let delegate = delegate else { return false }
let inputText: String = input.text let inputText: String = input.text
var state = state // var state = delegate.state //
// Megrez // Megrez
if input.isInvalid { if input.isInvalid {
@ -107,17 +105,13 @@ extension InputHandler {
// MARK: (Handle Candidates) // MARK: (Handle Candidates)
if [.ofCandidates, .ofSymbolTable].contains(state.type) { if [.ofCandidates, .ofSymbolTable].contains(state.type) {
return handleCandidate( return handleCandidate(input: input, errorCallback: errorCallback)
state: state, input: input, errorCallback: errorCallback
)
} }
// MARK: (Handle Associated Phrases) // MARK: (Handle Associated Phrases)
if state.type == .ofAssociates { if state.type == .ofAssociates {
if handleCandidate( if handleCandidate(input: input, errorCallback: errorCallback) {
state: state, input: input, errorCallback: errorCallback
) {
return true return true
} else { } else {
delegate.switchState(IMEState.ofEmpty()) delegate.switchState(IMEState.ofEmpty())
@ -127,12 +121,7 @@ extension InputHandler {
// MARK: 便使() (Handle Marking) // MARK: 便使() (Handle Marking)
if state.type == .ofMarking { if state.type == .ofMarking {
if handleMarkingState( if handleMarkingState(input: input, errorCallback: errorCallback) { return true }
state, input: input,
errorCallback: errorCallback
) {
return true
}
state = state.convertedToInputting state = state.convertedToInputting
delegate.switchState(state) delegate.switchState(state)
} }
@ -172,13 +161,10 @@ extension InputHandler {
} }
return true return true
} else if input.isShiftHold { // Tab Shift+Command+Space / } else if input.isShiftHold { // Tab Shift+Command+Space /
return handleInlineCandidateRotation( return handleInlineCandidateRotation(reverseOrder: input.isCommandHold, errorCallback: errorCallback)
state: state, reverseModifier: input.isCommandHold,
errorCallback: errorCallback
)
} }
} }
let candidateState: IMEStateProtocol = generateStateOfCandidates(state: state) let candidateState: IMEStateProtocol = generateStateOfCandidates()
if candidateState.candidates.isEmpty { if candidateState.candidates.isEmpty {
errorCallback("3572F238") errorCallback("3572F238")
} else { } else {
@ -191,56 +177,46 @@ extension InputHandler {
if let keyCodeType = KeyCode(rawValue: input.keyCode) { if let keyCodeType = KeyCode(rawValue: input.keyCode) {
switch keyCodeType { switch keyCodeType {
case .kEscape: return handleEsc(state: state) case .kEscape: return handleEsc()
case .kTab: case .kTab:
return handleInlineCandidateRotation( return handleInlineCandidateRotation(reverseOrder: input.isShiftHold, errorCallback: errorCallback)
state: state, reverseModifier: input.isShiftHold, errorCallback: errorCallback
)
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(state: state, errorCallback: errorCallback) return handleHome(errorCallback: errorCallback)
} else if input.isRight { // Ctrl+PgRt or Shift+PgRt } else if input.isRight { // Ctrl+PgRt or Shift+PgRt
return handleEnd(state: state, errorCallback: errorCallback) return handleEnd(errorCallback: errorCallback)
} }
} }
if input.isCursorBackward { // Forward if input.isCursorBackward { // Forward
return handleBackward( return handleBackward(input: input, errorCallback: errorCallback)
state: state, input: input, errorCallback: errorCallback
)
} }
if input.isCursorForward { // Backward if input.isCursorForward { // Backward
return handleForward( return handleForward(input: input, errorCallback: errorCallback)
state: state, input: input, errorCallback: errorCallback
)
} }
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( return handleInlineCandidateRotation(reverseOrder: false, errorCallback: errorCallback)
state: state, reverseModifier: false, errorCallback: errorCallback
)
} }
if input.isCursorClockLeft { if input.isCursorClockLeft {
return handleInlineCandidateRotation( return handleInlineCandidateRotation(reverseOrder: true, errorCallback: errorCallback)
state: state, reverseModifier: true, errorCallback: errorCallback
)
} }
} }
return handleClockKey(state: state, errorCallback: errorCallback) return handleClockKey(errorCallback: errorCallback)
} }
case .kHome: return handleHome(state: state, errorCallback: errorCallback) case .kHome: return handleHome(errorCallback: errorCallback)
case .kEnd: return handleEnd(state: state, errorCallback: errorCallback) case .kEnd: return handleEnd(errorCallback: errorCallback)
case .kBackSpace: case .kBackSpace:
return handleBackSpace(state: state, input: input, errorCallback: errorCallback) return handleBackSpace(input: input, errorCallback: errorCallback)
case .kWindowsDelete: case .kWindowsDelete:
return handleDelete(state: state, input: input, errorCallback: errorCallback) return handleDelete(input: input, errorCallback: errorCallback)
case .kCarriageReturn, .kLineFeed: case .kCarriageReturn, .kLineFeed:
return (input.isCommandHold && input.isControlHold) return (input.isCommandHold && input.isControlHold)
? (input.isOptionHold ? (input.isOptionHold
? handleCtrlOptionCommandEnter(state: state) ? handleCtrlOptionCommandEnter()
: handleCtrlCommandEnter(state: state)) : handleCtrlCommandEnter())
: handleEnter(state: state) : handleEnter()
default: break default: break
} }
} }
@ -258,7 +234,7 @@ extension InputHandler {
var inputting = generateStateOfInputting() var inputting = generateStateOfInputting()
inputting.textToCommit = textToCommit inputting.textToCommit = textToCommit
delegate.switchState(inputting) delegate.switchState(inputting)
let candidateState = generateStateOfCandidates(state: inputting) let candidateState = generateStateOfCandidates()
if candidateState.candidates.isEmpty { if candidateState.candidates.isEmpty {
errorCallback("B5127D8A") errorCallback("B5127D8A")
} else { } else {
@ -273,7 +249,7 @@ extension InputHandler {
// commit buffer ESC // commit buffer ESC
// Enter 使 commit buffer // Enter 使 commit buffer
// bool _ = // bool _ =
_ = handleEnter(state: state) _ = handleEnter()
delegate.switchState(IMEState.ofSymbolTable(node: CandidateNode.root)) delegate.switchState(IMEState.ofSymbolTable(node: CandidateNode.root))
return true return true
} }
@ -304,11 +280,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( if handlePunctuation(customPunctuation, errorCallback: errorCallback) {
customPunctuation,
state: state,
errorCallback: errorCallback
) {
return true return true
} }
@ -317,11 +289,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( if handlePunctuation(punctuation, errorCallback: errorCallback) {
punctuation,
state: state,
errorCallback: errorCallback
) {
return true return true
} }
@ -354,11 +322,7 @@ extension InputHandler {
return true return true
default: // case 0 default: // case 0
let letter = "_letter_\(inputText)" let letter = "_letter_\(inputText)"
if handlePunctuation( if handlePunctuation(letter, errorCallback: errorCallback) {
letter,
state: state,
errorCallback: errorCallback
) {
return true return true
} }
} }

View File

@ -84,15 +84,12 @@ extension InputHandler {
/// ///
/// - Parameters: /// - Parameters:
/// - currentState:
/// - Returns: /// - Returns:
func generateStateOfCandidates( func generateStateOfCandidates() -> IMEStateProtocol {
state currentState: IMEStateProtocol
) -> IMEStateProtocol {
IMEState.ofCandidates( IMEState.ofCandidates(
candidates: generateArrayOfCandidates(fixOrder: prefs.useFixecCandidateOrderOnSelection), candidates: generateArrayOfCandidates(fixOrder: prefs.useFixecCandidateOrderOnSelection),
displayTextSegments: compositor.walkedNodes.values, displayTextSegments: compositor.walkedNodes.values,
cursor: currentState.cursor cursor: delegate?.state.cursor ?? generateStateOfInputting().cursor
) )
} }
@ -110,9 +107,7 @@ extension InputHandler {
/// - Parameters: /// - Parameters:
/// - key: /// - key:
/// - Returns: /// - Returns:
public func generateStateOfAssociates( public func generateStateOfAssociates(withPair pair: Megrez.Compositor.KeyValuePaired) -> IMEStateProtocol {
withPair pair: Megrez.Compositor.KeyValuePaired
) -> IMEStateProtocol {
IMEState.ofAssociates( IMEState.ofAssociates(
candidates: generateArrayOfAssociates(withPair: pair)) candidates: generateArrayOfAssociates(withPair: pair))
} }
@ -121,16 +116,15 @@ extension InputHandler {
/// ///
/// - Parameters: /// - Parameters:
/// - state:
/// - input: /// - input:
/// - errorCallback: /// - errorCallback:
/// - Returns: SessionCtl IMK /// - Returns: SessionCtl IMK
func handleMarkingState( func handleMarkingState(
_ state: IMEStateProtocol,
input: InputSignalProtocol, input: InputSignalProtocol,
errorCallback: @escaping (String) -> Void errorCallback: @escaping (String) -> Void
) -> Bool { ) -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
let state = delegate.state
if input.isEsc { if input.isEsc {
delegate.switchState(generateStateOfInputting()) delegate.switchState(generateStateOfInputting())
@ -154,7 +148,7 @@ extension InputHandler {
errorCallback("9AAFAC00") errorCallback("9AAFAC00")
return true return true
} }
if !delegate.performUserPhraseOperation(with: state, addToFilter: false) { if !delegate.performUserPhraseOperation(addToFilter: false) {
errorCallback("5B69CC8D") errorCallback("5B69CC8D")
return true return true
} }
@ -168,7 +162,7 @@ extension InputHandler {
errorCallback("1F88B191") errorCallback("1F88B191")
return true return true
} }
if !delegate.performUserPhraseOperation(with: state, addToFilter: true) { if !delegate.performUserPhraseOperation(addToFilter: true) {
errorCallback("68D3C6C8") errorCallback("68D3C6C8")
return true return true
} }
@ -231,10 +225,10 @@ extension InputHandler {
/// - Returns: SessionCtl IMK /// - Returns: SessionCtl IMK
func handlePunctuation( func handlePunctuation(
_ customPunctuation: String, _ customPunctuation: String,
state: IMEStateProtocol,
errorCallback: @escaping (String) -> Void errorCallback: @escaping (String) -> Void
) -> Bool { ) -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
let state = delegate.state
if !currentLM.hasUnigramsFor(key: customPunctuation) { if !currentLM.hasUnigramsFor(key: customPunctuation) {
return false return false
@ -258,7 +252,7 @@ extension InputHandler {
// //
guard prefs.useSCPCTypingMode, composer.isEmpty else { return true } guard prefs.useSCPCTypingMode, composer.isEmpty else { return true }
let candidateState = generateStateOfCandidates(state: inputting) let candidateState = generateStateOfCandidates()
switch candidateState.candidates.count { switch candidateState.candidates.count {
case 2...: delegate.switchState(candidateState) case 2...: delegate.switchState(candidateState)
case 1: case 1:
@ -278,12 +272,10 @@ extension InputHandler {
/// Enter /// Enter
/// - Parameters: /// - Parameters:
/// - state:
/// - Returns: SessionCtl IMK /// - Returns: SessionCtl IMK
func handleEnter( func handleEnter() -> Bool {
state: IMEStateProtocol
) -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
let state = delegate.state
guard state.type == .ofInputting else { return false } guard state.type == .ofInputting else { return false }
delegate.switchState(IMEState.ofCommitting(textToCommit: state.displayedText)) delegate.switchState(IMEState.ofCommitting(textToCommit: state.displayedText))
@ -295,12 +287,10 @@ extension InputHandler {
/// Command+Enter /// Command+Enter
/// - Parameters: /// - Parameters:
/// - state:
/// - Returns: SessionCtl IMK /// - Returns: SessionCtl IMK
func handleCtrlCommandEnter( func handleCtrlCommandEnter() -> Bool {
state: IMEStateProtocol
) -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
let state = delegate.state
guard state.type == .ofInputting else { return false } guard state.type == .ofInputting else { return false }
var displayedText = compositor.keys.joined(separator: "-") var displayedText = compositor.keys.joined(separator: "-")
@ -322,12 +312,10 @@ extension InputHandler {
/// Command+Option+Enter Ruby /// Command+Option+Enter Ruby
/// - Parameters: /// - Parameters:
/// - state:
/// - Returns: SessionCtl IMK /// - Returns: SessionCtl IMK
func handleCtrlOptionCommandEnter( func handleCtrlOptionCommandEnter() -> Bool {
state: IMEStateProtocol
) -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
let state = delegate.state
guard state.type == .ofInputting else { return false } guard state.type == .ofInputting else { return false }
var composed = "" var composed = ""
@ -357,16 +345,15 @@ extension InputHandler {
/// BackSpace (macOS Delete) /// BackSpace (macOS Delete)
/// - Parameters: /// - Parameters:
/// - state:
/// - input: /// - input:
/// - errorCallback: /// - errorCallback:
/// - Returns: SessionCtl IMK /// - Returns: SessionCtl IMK
func handleBackSpace( func handleBackSpace(
state: IMEStateProtocol,
input: InputSignalProtocol, input: InputSignalProtocol,
errorCallback: @escaping (String) -> Void errorCallback: @escaping (String) -> Void
) -> Bool { ) -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
let state = delegate.state
guard state.type == .ofInputting else { return false } guard state.type == .ofInputting else { return false }
// macOS Shift+BackSpace // macOS Shift+BackSpace
@ -418,16 +405,15 @@ extension InputHandler {
/// PC Delete (macOS Fn+BackSpace) /// PC Delete (macOS Fn+BackSpace)
/// - Parameters: /// - Parameters:
/// - state:
/// - input: /// - input:
/// - errorCallback: /// - errorCallback:
/// - Returns: SessionCtl IMK /// - Returns: SessionCtl IMK
func handleDelete( func handleDelete(
state: IMEStateProtocol,
input: InputSignalProtocol, input: InputSignalProtocol,
errorCallback: @escaping (String) -> Void errorCallback: @escaping (String) -> Void
) -> Bool { ) -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
let state = delegate.state
guard state.type == .ofInputting else { return false } guard state.type == .ofInputting else { return false }
if input.isShiftHold { if input.isShiftHold {
@ -462,14 +448,13 @@ extension InputHandler {
/// 90 /// 90
/// - Parameters: /// - Parameters:
/// - state:
/// - errorCallback: /// - errorCallback:
/// - Returns: SessionCtl IMK /// - Returns: SessionCtl IMK
func handleClockKey( func handleClockKey(
state: IMEStateProtocol,
errorCallback: @escaping (String) -> Void errorCallback: @escaping (String) -> Void
) -> Bool { ) -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
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") errorCallback("9B6F908D")
@ -482,14 +467,13 @@ extension InputHandler {
/// Home /// Home
/// - Parameters: /// - Parameters:
/// - state:
/// - errorCallback: /// - errorCallback:
/// - Returns: SessionCtl IMK /// - Returns: SessionCtl IMK
func handleHome( func handleHome(
state: IMEStateProtocol,
errorCallback: @escaping (String) -> Void errorCallback: @escaping (String) -> Void
) -> Bool { ) -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
let state = delegate.state
guard state.type == .ofInputting else { return false } guard state.type == .ofInputting else { return false }
if !composer.isEmpty { if !composer.isEmpty {
@ -513,14 +497,13 @@ extension InputHandler {
/// End /// End
/// - Parameters: /// - Parameters:
/// - state:
/// - errorCallback: /// - errorCallback:
/// - Returns: SessionCtl IMK /// - Returns: SessionCtl IMK
func handleEnd( func handleEnd(
state: IMEStateProtocol,
errorCallback: @escaping (String) -> Void errorCallback: @escaping (String) -> Void
) -> Bool { ) -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
let state = delegate.state
guard state.type == .ofInputting else { return false } guard state.type == .ofInputting else { return false }
if !composer.isEmpty { if !composer.isEmpty {
@ -544,12 +527,10 @@ extension InputHandler {
/// Esc /// Esc
/// - Parameters: /// - Parameters:
/// - state:
/// - Returns: SessionCtl IMK /// - Returns: SessionCtl IMK
func handleEsc( func handleEsc() -> Bool {
state: IMEStateProtocol
) -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
let state = delegate.state
guard state.type == .ofInputting else { return false } guard state.type == .ofInputting else { return false }
if prefs.escToCleanInputBuffer { if prefs.escToCleanInputBuffer {
@ -573,16 +554,15 @@ extension InputHandler {
/// ///
/// - Parameters: /// - Parameters:
/// - state:
/// - input: /// - input:
/// - errorCallback: /// - errorCallback:
/// - Returns: SessionCtl IMK /// - Returns: SessionCtl IMK
func handleForward( func handleForward(
state: IMEStateProtocol,
input: InputSignalProtocol, input: InputSignalProtocol,
errorCallback: @escaping (String) -> Void errorCallback: @escaping (String) -> Void
) -> Bool { ) -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
let state = delegate.state
guard state.type == .ofInputting else { return false } guard state.type == .ofInputting else { return false }
if !composer.isEmpty { if !composer.isEmpty {
@ -612,7 +592,7 @@ extension InputHandler {
} }
} else if input.isOptionHold { } else if input.isOptionHold {
if input.isControlHold { if input.isControlHold {
return handleEnd(state: state, errorCallback: errorCallback) return handleEnd(errorCallback: errorCallback)
} }
// //
if !compositor.jumpCursorBySpan(to: .front) { if !compositor.jumpCursorBySpan(to: .front) {
@ -641,16 +621,15 @@ extension InputHandler {
/// ///
/// - Parameters: /// - Parameters:
/// - state:
/// - input: /// - input:
/// - errorCallback: /// - errorCallback:
/// - Returns: SessionCtl IMK /// - Returns: SessionCtl IMK
func handleBackward( func handleBackward(
state: IMEStateProtocol,
input: InputSignalProtocol, input: InputSignalProtocol,
errorCallback: @escaping (String) -> Void errorCallback: @escaping (String) -> Void
) -> Bool { ) -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
let state = delegate.state
guard state.type == .ofInputting else { return false } guard state.type == .ofInputting else { return false }
if !composer.isEmpty { if !composer.isEmpty {
@ -680,7 +659,7 @@ extension InputHandler {
} }
} else if input.isOptionHold { } else if input.isOptionHold {
if input.isControlHold { if input.isControlHold {
return handleHome(state: state, errorCallback: errorCallback) return handleHome(errorCallback: errorCallback)
} }
// //
if !compositor.jumpCursorBySpan(to: .rear) { if !compositor.jumpCursorBySpan(to: .rear) {
@ -709,16 +688,15 @@ extension InputHandler {
/// ///
/// - Parameters: /// - Parameters:
/// - state: /// - reverseOrder:
/// - reverseModifier:
/// - errorCallback: /// - errorCallback:
/// - Returns: SessionCtl IMK /// - Returns: SessionCtl IMK
func handleInlineCandidateRotation( func handleInlineCandidateRotation(
state: IMEStateProtocol, reverseOrder: Bool,
reverseModifier: Bool,
errorCallback: @escaping (String) -> Void errorCallback: @escaping (String) -> Void
) -> Bool { ) -> Bool {
guard let delegate = delegate else { return false } guard let delegate = delegate else { return false }
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 {
@ -772,12 +750,12 @@ extension InputHandler {
if candidates[0] == currentPaired { if candidates[0] == currentPaired {
/// ///
/// ///
currentIndex = reverseModifier ? candidates.count - 1 : 1 currentIndex = reverseOrder ? candidates.count - 1 : 1
} }
} else { } else {
for candidate in candidates { for candidate in candidates {
if candidate == currentPaired { if candidate == currentPaired {
if reverseModifier { if reverseOrder {
if currentIndex == 0 { if currentIndex == 0 {
currentIndex = candidates.count - 1 currentIndex = candidates.count - 1
} else { } else {

View File

@ -22,9 +22,7 @@ extension SessionCtl: InputHandlerDelegate {
candidatePairSelected(at: index) candidatePairSelected(at: index)
} }
public func performUserPhraseOperation(with state: IMEStateProtocol, addToFilter: Bool) public func performUserPhraseOperation(addToFilter: Bool) -> Bool {
-> Bool
{
guard state.type == .ofMarking else { return false } guard state.type == .ofMarking else { return false }
if !LMMgr.writeUserPhrase( if !LMMgr.writeUserPhrase(
state.data.userPhraseDumped, inputMode: inputMode, state.data.userPhraseDumped, inputMode: inputMode,