KeyHandler // Upgrade certain condition structures.

This commit is contained in:
ShikiSuen 2022-07-30 23:08:47 +08:00
parent c68d7dd151
commit 02abb79668
2 changed files with 43 additions and 47 deletions

View File

@ -293,14 +293,12 @@ extension KeyHandler {
let match: String =
(state is InputState.AssociatedPhrases) ? input.inputTextIgnoringModifiers ?? "" : inputText
var j = 0
while j < ctlCandidateCurrent.keyLabels.count {
for j in 0..<ctlCandidateCurrent.keyLabels.count {
let label: CandidateKeyLabel = ctlCandidateCurrent.keyLabels[j]
if match.compare(label.key, options: .caseInsensitive, range: nil, locale: .current) == .orderedSame {
index = j
break
}
j += 1
}
if index != NSNotFound {

View File

@ -57,47 +57,46 @@ extension KeyHandler {
if readingCursorIndex + spanningLength <= compositor.cursor {
composedStringCursorIndex += strNodeValue.utf16.count
readingCursorIndex += spanningLength
} else {
if codepointCount == spanningLength {
var i = 0
while i < codepointCount, readingCursorIndex < compositor.cursor {
composedStringCursorIndex += arrSplit[i].utf16.count
readingCursorIndex += 1
i += 1
}
continue
}
if codepointCount == spanningLength {
for i in 0..<codepointCount {
guard readingCursorIndex < compositor.cursor else { continue }
composedStringCursorIndex += arrSplit[i].utf16.count
readingCursorIndex += 1
}
continue
}
guard readingCursorIndex < compositor.cursor else { continue }
composedStringCursorIndex += strNodeValue.utf16.count
readingCursorIndex += spanningLength
readingCursorIndex = min(readingCursorIndex, compositor.cursor)
///
///
///
///
///
switch compositor.cursor {
case compositor.readings.count...:
// compositor.cursor readings.count Megrez
tooltipParameterRef[0] = compositor.readings[compositor.cursor - 1]
case 0:
tooltipParameterRef[1] = compositor.readings[compositor.cursor]
default:
tooltipParameterRef[0] = compositor.readings[compositor.cursor - 1]
tooltipParameterRef[1] = compositor.readings[compositor.cursor]
}
///
guard tooltipParameterRef != ["", ""] else { continue }
for (i, _) in tooltipParameterRef.enumerated() {
if tooltipParameterRef[i].isEmpty { continue }
if tooltipParameterRef[i].contains("_") { continue }
if mgrPrefs.showHanyuPinyinInCompositionBuffer { // ->->調
tooltipParameterRef[i] = Tekkon.restoreToneOneInZhuyinKey(target: tooltipParameterRef[i])
tooltipParameterRef[i] = Tekkon.cnvPhonaToHanyuPinyin(target: tooltipParameterRef[i])
tooltipParameterRef[i] = Tekkon.cnvHanyuPinyinToTextbookStyle(target: tooltipParameterRef[i])
} else {
if readingCursorIndex < compositor.cursor {
composedStringCursorIndex += strNodeValue.utf16.count
readingCursorIndex += spanningLength
readingCursorIndex = min(readingCursorIndex, compositor.cursor)
///
///
///
///
///
switch compositor.cursor {
case compositor.readings.count...:
// compositor.cursor readings.count Megrez
tooltipParameterRef[0] = compositor.readings[compositor.cursor - 1]
case 0:
tooltipParameterRef[1] = compositor.readings[compositor.cursor]
default:
tooltipParameterRef[0] = compositor.readings[compositor.cursor - 1]
tooltipParameterRef[1] = compositor.readings[compositor.cursor]
}
///
for (i, _) in tooltipParameterRef.enumerated() {
if tooltipParameterRef[i].isEmpty { continue }
if tooltipParameterRef[i].contains("_") { continue }
if mgrPrefs.showHanyuPinyinInCompositionBuffer { // ->->調
tooltipParameterRef[i] = Tekkon.restoreToneOneInZhuyinKey(target: tooltipParameterRef[i])
tooltipParameterRef[i] = Tekkon.cnvPhonaToHanyuPinyin(target: tooltipParameterRef[i])
tooltipParameterRef[i] = Tekkon.cnvHanyuPinyinToTextbookStyle(target: tooltipParameterRef[i])
} else {
tooltipParameterRef[i] = Tekkon.cnvZhuyinChainToTextbookReading(target: tooltipParameterRef[i])
}
}
}
tooltipParameterRef[i] = Tekkon.cnvZhuyinChainToTextbookReading(target: tooltipParameterRef[i])
}
}
}
@ -126,10 +125,9 @@ extension KeyHandler {
//
var cleanedComposition = ""
for theChar in composedText {
if let charCode = theChar.utf16.first {
if !(theChar.isASCII && !(charCode.isPrintable)) {
cleanedComposition += String(theChar)
}
guard let charCode = theChar.utf16.first else { continue }
if !(theChar.isASCII && !(charCode.isPrintable)) {
cleanedComposition += String(theChar)
}
}