Repo // Call candidatePairHighlightChanged() when appropriate.
This commit is contained in:
parent
fc49bebc5d
commit
625897a744
|
@ -88,6 +88,7 @@ public class CtlCandidateTDK: CtlCandidate, NSWindowDelegate {
|
|||
reverseLookupResult = delegate?.reverseLookup(for: currentCandidateText) ?? []
|
||||
Self.thePool.reverseLookupResult = reverseLookupResult
|
||||
}
|
||||
delegate?.candidatePairHighlightChanged(at: highlightedIndex)
|
||||
DispatchQueue.main.async { [self] in
|
||||
window.isOpaque = false
|
||||
window.backgroundColor = .clear
|
||||
|
|
|
@ -69,14 +69,20 @@ public extension SessionCtl {
|
|||
/// IMK 選字窗限定函式,只要選字窗內的高亮內容選擇出現變化了、就會呼叫這個函式。
|
||||
/// - Parameter currentSelection: 已經高亮選中的候選字詞內容。
|
||||
override func candidateSelectionChanged(_ currentSelection: NSAttributedString!) {
|
||||
guard let currentCandidate = currentSelection?.string, !currentCandidate.isEmpty else { return }
|
||||
let annotation = reverseLookup(for: currentCandidate).joined(separator: "\n")
|
||||
guard let candidateString = currentSelection?.string, !candidateString.isEmpty else { return }
|
||||
// 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 }
|
||||
vCLog("Current Annotation: \(annotation)")
|
||||
DispatchQueue.main.async { [self] in
|
||||
guard let imkCandidates = candidateUI as? CtlCandidateIMK else { return }
|
||||
imkCandidates.showAnnotation(.init(string: annotation))
|
||||
}
|
||||
// Handle candidatePairHighlightChanged().
|
||||
guard state.type == .ofCandidates else { return }
|
||||
var indexDeducted = 0
|
||||
fixIndexForIMKCandidates(&indexDeducted, source: candidateString)
|
||||
candidatePairHighlightChanged(at: indexDeducted)
|
||||
}
|
||||
|
||||
/// IMK 選字窗限定函式,只要選字窗確認了某個候選字詞的選擇、就會呼叫這個函式。
|
||||
|
@ -85,6 +91,7 @@ public extension SessionCtl {
|
|||
override func candidateSelected(_ candidateString: NSAttributedString!) {
|
||||
let candidateString: String = candidateString?.string ?? ""
|
||||
if state.type == .ofAssociates {
|
||||
// 聯想詞的 Shift+選字鍵的處理已經在其它位置實作完成。
|
||||
if !PrefMgr.shared.alsoConfirmAssociatedCandidatesByEnter {
|
||||
switchState(IMEState.ofAbortion())
|
||||
return
|
||||
|
@ -93,11 +100,42 @@ public extension SessionCtl {
|
|||
|
||||
var indexDeducted = 0
|
||||
|
||||
// 注意:下文中的不可列印字元是用來方便在 IMEState 當中用來分割資料的。
|
||||
func handleIMKCandidatesSelected(
|
||||
_ candidates: [(keyArray: [String], value: String)], prefix: String = ""
|
||||
// 分類符號選單不會出現同符異音項、不需要康熙 / JIS 轉換,所以使用簡化過的處理方式。
|
||||
func fixSymbolIndexForIMKCandidates() {
|
||||
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 }
|
||||
let candidates = state.candidates
|
||||
for (i, neta) in candidates.enumerated() {
|
||||
let theConverted = ChineseConverter.kanjiConversionIfRequired(neta.value)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue