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 false
} }
open func candidateIndexAtKeyLabelIndex(_: Int) -> Int { open func candidateIndexAtKeyLabelIndex(_: Int) -> Int? {
Int.max Int.max
} }

View File

@ -42,7 +42,7 @@ public protocol CtlCandidateProtocol {
func showPreviousLine() -> Bool func showPreviousLine() -> Bool
func highlightNextCandidate() -> Bool func highlightNextCandidate() -> Bool
func highlightPreviousCandidate() -> Bool func highlightPreviousCandidate() -> Bool
func candidateIndexAtKeyLabelIndex(_: Int) -> Int func candidateIndexAtKeyLabelIndex(_: Int) -> Int?
func set(windowTopLeftPoint: NSPoint, bottomOutOfScreenAdjustmentHeight height: Double, useGCD: Bool) func set(windowTopLeftPoint: NSPoint, bottomOutOfScreenAdjustmentHeight height: Double, useGCD: Bool)
} }

View File

@ -141,8 +141,7 @@ extension InputHandler {
} }
if index != NSNotFound { if index != NSNotFound {
let candidateIndex = ctlCandidate.candidateIndexAtKeyLabelIndex(index) if let candidateIndex = ctlCandidate.candidateIndexAtKeyLabelIndex(index) {
if candidateIndex != -114_514 {
delegate.candidateSelectionCalledByInputHandler(at: candidateIndex) delegate.candidateSelectionCalledByInputHandler(at: candidateIndex)
return true return true
} }
@ -185,13 +184,10 @@ extension InputHandler {
} }
if shouldAutoSelectCandidate { if shouldAutoSelectCandidate {
let candidateIndex = ctlCandidate.candidateIndexAtKeyLabelIndex(0) guard let candidateIndex = ctlCandidate.candidateIndexAtKeyLabelIndex(0) else { return true }
if candidateIndex != -114_514 { delegate.candidateSelectionCalledByInputHandler(at: candidateIndex)
delegate.candidateSelectionCalledByInputHandler(at: candidateIndex) delegate.switchState(IMEState.ofAbortion())
delegate.switchState(IMEState.ofAbortion()) return handleInput(event: input)
return handleInput(event: input)
}
return true
} }
} }

View File

@ -141,7 +141,7 @@ public class CtlCandidateIMK: IMKCandidates, CtlCandidateProtocol {
} }
// IMK IMK 使 // IMK IMK 使
public func candidateIndexAtKeyLabelIndex(_: Int) -> Int { 0 } public func candidateIndexAtKeyLabelIndex(_: Int) -> Int? { 0 }
public var highlightedIndex: Int { public var highlightedIndex: Int {
get { selectedCandidate() } get { selectedCandidate() }