SessionCtl // Use annotationSelected().

This commit is contained in:
ShikiSuen 2023-05-29 21:22:15 +08:00
parent 785840c02e
commit 4888a0dc54
1 changed files with 8 additions and 5 deletions

View File

@ -70,19 +70,22 @@ public extension SessionCtl {
/// - Parameter currentSelection: /// - Parameter currentSelection:
override func candidateSelectionChanged(_ currentSelection: NSAttributedString!) { override func candidateSelectionChanged(_ currentSelection: NSAttributedString!) {
guard let candidateString = currentSelection?.string, !candidateString.isEmpty else { return } guard let candidateString = currentSelection?.string, !candidateString.isEmpty else { return }
// Handle candidatePairHighlightChanged().
var indexDeducted = 0
fixIndexForIMKCandidates(&indexDeducted, source: candidateString)
if state.type == .ofCandidates {
candidatePairHighlightChanged(at: indexDeducted)
}
let realCandidateString = state.candidates[indexDeducted].value
// Handle IMK Annotation... We just use this to tell Apple that this never works in IMKCandidates. // Handle IMK Annotation... We just use this to tell Apple that this never works in IMKCandidates.
DispatchQueue.main.async { [self] in DispatchQueue.main.async { [self] in
let annotation = reverseLookup(for: candidateString).joined(separator: "\n") let annotation = reverseLookup(for: candidateString).joined(separator: "\n")
guard !annotation.isEmpty else { return } guard !annotation.isEmpty else { return }
vCLog("Current Annotation: \(annotation)") vCLog("Current Annotation: \(annotation)")
guard let imkCandidates = candidateUI as? CtlCandidateIMK else { return } guard let imkCandidates = candidateUI as? CtlCandidateIMK else { return }
annotationSelected(.init(string: annotation), forCandidate: .init(string: realCandidateString))
imkCandidates.showAnnotation(.init(string: annotation)) imkCandidates.showAnnotation(.init(string: annotation))
} }
// Handle candidatePairHighlightChanged().
guard state.type == .ofCandidates else { return }
var indexDeducted = 0
fixIndexForIMKCandidates(&indexDeducted, source: candidateString)
candidatePairHighlightChanged(at: indexDeducted)
} }
/// IMK /// IMK