Repo // Make candidateIndexAtKeyLabelIndex() nullable.

This commit is contained in:
ShikiSuen 2023-02-20 20:20:49 +08:00
parent 2289be50b6
commit 888e6a9ddf
4 changed files with 8 additions and 12 deletions

View File

@ -109,7 +109,7 @@ open class CtlCandidate: NSWindowController, CtlCandidateProtocol {
false
}
open func candidateIndexAtKeyLabelIndex(_: Int) -> Int {
open func candidateIndexAtKeyLabelIndex(_: Int) -> Int? {
Int.max
}

View File

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

View File

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

View File

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