InputHandler // Refactor handleCandidate().
This commit is contained in:
parent
8562c35535
commit
950c9ea554
|
@ -150,25 +150,18 @@ extension InputHandler {
|
||||||
if !input.isShiftHold { return false }
|
if !input.isShiftHold { return false }
|
||||||
}
|
}
|
||||||
|
|
||||||
var index: Int = NSNotFound
|
var index: Int?
|
||||||
let match: String =
|
let matched: String =
|
||||||
(state.type == .ofAssociates) ? input.inputTextIgnoringModifiers ?? "" : input.text
|
(state.type == .ofAssociates) ? input.inputTextIgnoringModifiers ?? "" : input.text
|
||||||
|
checkSelectionKey: for keyPair in delegate.selectionKeys.enumerated() {
|
||||||
let selectionKeys = delegate.selectionKeys
|
guard matched.lowercased() == keyPair.element.lowercased() else { continue }
|
||||||
|
index = Int(keyPair.offset)
|
||||||
for j in 0 ..< selectionKeys.count {
|
break checkSelectionKey
|
||||||
let label = selectionKeys.map(\.description)[j]
|
|
||||||
if match.compare(label, options: .caseInsensitive, range: nil, locale: .current) == .orderedSame {
|
|
||||||
index = j
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if index != NSNotFound {
|
if let index = index, let candidateIndex = ctlCandidate.candidateIndexAtKeyLabelIndex(index) {
|
||||||
if let candidateIndex = ctlCandidate.candidateIndexAtKeyLabelIndex(index) {
|
delegate.candidateSelectionConfirmedByInputHandler(at: candidateIndex)
|
||||||
delegate.candidateSelectionConfirmedByInputHandler(at: candidateIndex)
|
return true
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if state.type == .ofAssociates { return false }
|
if state.type == .ofAssociates { return false }
|
||||||
|
|
Loading…
Reference in New Issue