Repo // Call candidatePairHighlightChanged() when appropriate.

This commit is contained in:
ShikiSuen 2023-03-09 16:32:48 +08:00
parent fc49bebc5d
commit 625897a744
2 changed files with 60 additions and 46 deletions

View File

@ -88,6 +88,7 @@ public class CtlCandidateTDK: CtlCandidate, NSWindowDelegate {
reverseLookupResult = delegate?.reverseLookup(for: currentCandidateText) ?? [] reverseLookupResult = delegate?.reverseLookup(for: currentCandidateText) ?? []
Self.thePool.reverseLookupResult = reverseLookupResult Self.thePool.reverseLookupResult = reverseLookupResult
} }
delegate?.candidatePairHighlightChanged(at: highlightedIndex)
DispatchQueue.main.async { [self] in DispatchQueue.main.async { [self] in
window.isOpaque = false window.isOpaque = false
window.backgroundColor = .clear window.backgroundColor = .clear

View File

@ -69,14 +69,20 @@ public extension SessionCtl {
/// IMK /// IMK
/// - Parameter currentSelection: /// - Parameter currentSelection:
override func candidateSelectionChanged(_ currentSelection: NSAttributedString!) { override func candidateSelectionChanged(_ currentSelection: NSAttributedString!) {
guard let currentCandidate = currentSelection?.string, !currentCandidate.isEmpty else { return } guard let candidateString = currentSelection?.string, !candidateString.isEmpty else { return }
let annotation = reverseLookup(for: currentCandidate).joined(separator: "\n") // Handle IMK Annotation... We just use this to tell Apple that this never works in IMKCandidates.
DispatchQueue.main.async { [self] in
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)")
DispatchQueue.main.async { [self] in
guard let imkCandidates = candidateUI as? CtlCandidateIMK else { return } guard let imkCandidates = candidateUI as? CtlCandidateIMK else { return }
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
@ -85,6 +91,7 @@ public extension SessionCtl {
override func candidateSelected(_ candidateString: NSAttributedString!) { override func candidateSelected(_ candidateString: NSAttributedString!) {
let candidateString: String = candidateString?.string ?? "" let candidateString: String = candidateString?.string ?? ""
if state.type == .ofAssociates { if state.type == .ofAssociates {
// Shift+
if !PrefMgr.shared.alsoConfirmAssociatedCandidatesByEnter { if !PrefMgr.shared.alsoConfirmAssociatedCandidatesByEnter {
switchState(IMEState.ofAbortion()) switchState(IMEState.ofAbortion())
return return
@ -93,11 +100,42 @@ public extension SessionCtl {
var indexDeducted = 0 var indexDeducted = 0
// 便 IMEState // / JIS 使
func handleIMKCandidatesSelected( func fixSymbolIndexForIMKCandidates() {
_ candidates: [(keyArray: [String], value: String)], prefix: String = "" for (i, neta) in state.candidates.enumerated() {
if candidateString == neta.value {
indexDeducted = i
break
}
}
}
if state.type == .ofAssociates {
fixIndexForIMKCandidates(&indexDeducted, prefix: "", source: candidateString)
} else if state.type == .ofSymbolTable {
fixSymbolIndexForIMKCandidates()
} else if state.type == .ofCandidates {
guard !state.candidates.isEmpty else { return }
if state.candidates[0].keyArray.description.contains("_punctuation") {
fixSymbolIndexForIMKCandidates() //
} else {
fixIndexForIMKCandidates(&indexDeducted, source: candidateString)
}
}
candidatePairSelectionConfirmed(at: indexDeducted)
}
/// IMKCandidates
/// - Remark: `\u{1A`便 IMEState
/// - Parameters:
/// - prefix:
/// - indexToFix:
/// - candidateString: IMKCandidates
private func fixIndexForIMKCandidates(
_ indexDeducted: inout Int, prefix: String = "", source candidateString: String
) { ) {
guard let separator = inputHandler?.keySeparator else { return } guard let separator = inputHandler?.keySeparator else { return }
let candidates = state.candidates
for (i, neta) in candidates.enumerated() { for (i, neta) in candidates.enumerated() {
let theConverted = ChineseConverter.kanjiConversionIfRequired(neta.value) let theConverted = ChineseConverter.kanjiConversionIfRequired(neta.value)
let netaShown = (neta.value == theConverted) let netaShown = (neta.value == theConverted)
@ -128,29 +166,4 @@ public extension SessionCtl {
} }
} }
} }
// / JIS 使
func handleSymbolCandidatesSelected(_ candidates: [(keyArray: [String], value: String)]) {
for (i, neta) in candidates.enumerated() {
if candidateString == neta.value {
indexDeducted = i
break
}
}
}
if state.type == .ofAssociates {
handleIMKCandidatesSelected(state.candidates, prefix: "")
} else if state.type == .ofSymbolTable {
handleSymbolCandidatesSelected(state.candidates)
} else if state.type == .ofCandidates {
guard !state.candidates.isEmpty else { return }
if state.candidates[0].keyArray.description.contains("_punctuation") {
handleSymbolCandidatesSelected(state.candidates) //
} else {
handleIMKCandidatesSelected(state.candidates)
}
}
candidatePairSelectionConfirmed(at: indexDeducted)
}
} }