diff --git a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/CtlCandidate.swift b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/CtlCandidate.swift index a84ef6d7..6b9a90d1 100644 --- a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/CtlCandidate.swift +++ b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/CtlCandidate.swift @@ -109,7 +109,7 @@ open class CtlCandidate: NSWindowController, CtlCandidateProtocol { false } - open func candidateIndexAtKeyLabelIndex(_: Int) -> Int { + open func candidateIndexAtKeyLabelIndex(_: Int) -> Int? { Int.max } diff --git a/Packages/vChewing_Shared/Sources/Shared/Protocols/CtlCandidateProtocol.swift b/Packages/vChewing_Shared/Sources/Shared/Protocols/CtlCandidateProtocol.swift index d891a44e..07317c78 100644 --- a/Packages/vChewing_Shared/Sources/Shared/Protocols/CtlCandidateProtocol.swift +++ b/Packages/vChewing_Shared/Sources/Shared/Protocols/CtlCandidateProtocol.swift @@ -42,7 +42,7 @@ public protocol CtlCandidateProtocol { func showPreviousLine() -> Bool func highlightNextCandidate() -> Bool func highlightPreviousCandidate() -> Bool - func candidateIndexAtKeyLabelIndex(_: Int) -> Int + func candidateIndexAtKeyLabelIndex(_: Int) -> Int? func set(windowTopLeftPoint: NSPoint, bottomOutOfScreenAdjustmentHeight height: Double, useGCD: Bool) } diff --git a/Source/Modules/InputHandler_HandleCandidate.swift b/Source/Modules/InputHandler_HandleCandidate.swift index 65005013..3043ee12 100644 --- a/Source/Modules/InputHandler_HandleCandidate.swift +++ b/Source/Modules/InputHandler_HandleCandidate.swift @@ -141,8 +141,7 @@ extension InputHandler { } if index != NSNotFound { - let candidateIndex = ctlCandidate.candidateIndexAtKeyLabelIndex(index) - if candidateIndex != -114_514 { + if let candidateIndex = ctlCandidate.candidateIndexAtKeyLabelIndex(index) { delegate.candidateSelectionCalledByInputHandler(at: candidateIndex) return true } @@ -185,13 +184,10 @@ extension InputHandler { } if shouldAutoSelectCandidate { - let candidateIndex = ctlCandidate.candidateIndexAtKeyLabelIndex(0) - if candidateIndex != -114_514 { - delegate.candidateSelectionCalledByInputHandler(at: candidateIndex) - delegate.switchState(IMEState.ofAbortion()) - return handleInput(event: input) - } - return true + guard let candidateIndex = ctlCandidate.candidateIndexAtKeyLabelIndex(0) else { return true } + delegate.candidateSelectionCalledByInputHandler(at: candidateIndex) + delegate.switchState(IMEState.ofAbortion()) + return handleInput(event: input) } } diff --git a/Source/Modules/UIModules/CandidateUI/IMKCandidatesImpl.swift b/Source/Modules/UIModules/CandidateUI/IMKCandidatesImpl.swift index 26462f1a..a1a751eb 100644 --- a/Source/Modules/UIModules/CandidateUI/IMKCandidatesImpl.swift +++ b/Source/Modules/UIModules/CandidateUI/IMKCandidatesImpl.swift @@ -141,7 +141,7 @@ public class CtlCandidateIMK: IMKCandidates, CtlCandidateProtocol { } // IMK 選字窗目前無法實作該函式。威注音 IMK 選字窗目前也不需要使用該函式。 - public func candidateIndexAtKeyLabelIndex(_: Int) -> Int { 0 } + public func candidateIndexAtKeyLabelIndex(_: Int) -> Int? { 0 } public var highlightedIndex: Int { get { selectedCandidate() }