diff --git a/Packages/vChewing_Shared/Sources/Shared/Protocols/CtlCandidateProtocol.swift b/Packages/vChewing_Shared/Sources/Shared/Protocols/CtlCandidateProtocol.swift index 6391891e..5fadb50c 100644 --- a/Packages/vChewing_Shared/Sources/Shared/Protocols/CtlCandidateProtocol.swift +++ b/Packages/vChewing_Shared/Sources/Shared/Protocols/CtlCandidateProtocol.swift @@ -14,6 +14,7 @@ public protocol CtlCandidateDelegate { func candidatePairHighlightChanged(at index: Int) func candidatePairRightClicked(at index: Int, action: CandidateContextMenuAction) func candidates(_ sender: Any!) -> [Any]! + func deductCandidateIndex(from candidateString: String) -> Int func resetCandidateWindowOrigin() @discardableResult func reverseLookup(for value: String) -> [String] var selectionKeys: String { get } diff --git a/Source/Modules/UIModules/CandidateUI/IMKCandidatesImpl.swift b/Source/Modules/UIModules/CandidateUI/IMKCandidatesImpl.swift index a0671030..063f47c9 100644 --- a/Source/Modules/UIModules/CandidateUI/IMKCandidatesImpl.swift +++ b/Source/Modules/UIModules/CandidateUI/IMKCandidatesImpl.swift @@ -148,7 +148,11 @@ public class CtlCandidateIMK: IMKCandidates, CtlCandidateProtocol { public func candidateIndexAtKeyLabelIndex(_: Int) -> Int? { 0 } public var highlightedIndex: Int { - get { selectedCandidate() } + get { + let returned = selectedCandidate() + guard let strCurrentCandidate = selectedCandidateString() else { return returned } + return delegate?.deductCandidateIndex(from: strCurrentCandidate.string) ?? returned + } set { selectCandidate(withIdentifier: newValue) } } }