ctlIME // Fix a matching bug in handleCandidatesSelected(), etc.

This commit is contained in:
ShikiSuen 2022-08-19 18:01:20 +08:00
parent ebf59b594c
commit 988c40bed7
1 changed files with 13 additions and 4 deletions

View File

@ -281,12 +281,17 @@ class ctlInputMethod: IMKInputController {
_ = sender // _ = sender //
var arrResult = [String]() var arrResult = [String]()
// 便 InputState
func handleCandidatesPrepared(_ candidates: [(String, String)], prefix: String = "") { func handleCandidatesPrepared(_ candidates: [(String, String)], prefix: String = "") {
for theCandidate in candidates { for theCandidate in candidates {
let theConverted = IME.kanjiConversionIfRequired(theCandidate.1) let theConverted = IME.kanjiConversionIfRequired(theCandidate.1)
var result = (theCandidate.1 == theConverted) ? theCandidate.1 : "\(theConverted)(\(theCandidate.1))" var result = (theCandidate.1 == theConverted) ? theCandidate.1 : "\(theConverted)\u{1A}(\(theCandidate.1))"
if arrResult.contains(result) { if arrResult.contains(result) {
result = "\(result)(\(theCandidate.0))" let reading: String =
mgrPrefs.showHanyuPinyinInCompositionBuffer
? Tekkon.cnvPhonaToHanyuPinyin(target: Tekkon.restoreToneOneInZhuyinKey(target: theCandidate.0))
: theCandidate.0
result = "\(result)\u{17}(\(reading))"
} }
arrResult.append(prefix + result) arrResult.append(prefix + result)
} }
@ -327,11 +332,15 @@ class ctlInputMethod: IMKInputController {
var indexDeducted = 0 var indexDeducted = 0
// 便 InputState
func handleCandidatesSelected(_ candidates: [(String, String)], prefix: String = "") { func handleCandidatesSelected(_ candidates: [(String, String)], prefix: String = "") {
for (i, neta) in candidates.enumerated() { for (i, neta) in candidates.enumerated() {
let theConverted = IME.kanjiConversionIfRequired(neta.1) let theConverted = IME.kanjiConversionIfRequired(neta.1)
let netaShown = (neta.1 == theConverted) ? neta.1 : "\(theConverted)(\(neta.1))" let netaShown = (neta.1 == theConverted) ? neta.1 : "\(theConverted)\u{1A}(\(neta.1))"
let netaShownWithPronunciation = "\(theConverted)(\(neta.0))" let reading: String =
mgrPrefs.showHanyuPinyinInCompositionBuffer
? Tekkon.cnvPhonaToHanyuPinyin(target: Tekkon.restoreToneOneInZhuyinKey(target: neta.0)) : neta.0
let netaShownWithPronunciation = "\(netaShown)\u{17}(\(reading))"
if candidateString.string == prefix + netaShownWithPronunciation { if candidateString.string == prefix + netaShownWithPronunciation {
indexDeducted = i indexDeducted = i
break break