KeyHandler // Upgrade certain condition structures.
This commit is contained in:
parent
c68d7dd151
commit
02abb79668
|
@ -293,14 +293,12 @@ extension KeyHandler {
|
||||||
let match: String =
|
let match: String =
|
||||||
(state is InputState.AssociatedPhrases) ? input.inputTextIgnoringModifiers ?? "" : inputText
|
(state is InputState.AssociatedPhrases) ? input.inputTextIgnoringModifiers ?? "" : inputText
|
||||||
|
|
||||||
var j = 0
|
for j in 0..<ctlCandidateCurrent.keyLabels.count {
|
||||||
while j < ctlCandidateCurrent.keyLabels.count {
|
|
||||||
let label: CandidateKeyLabel = ctlCandidateCurrent.keyLabels[j]
|
let label: CandidateKeyLabel = ctlCandidateCurrent.keyLabels[j]
|
||||||
if match.compare(label.key, options: .caseInsensitive, range: nil, locale: .current) == .orderedSame {
|
if match.compare(label.key, options: .caseInsensitive, range: nil, locale: .current) == .orderedSame {
|
||||||
index = j
|
index = j
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
j += 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if index != NSNotFound {
|
if index != NSNotFound {
|
||||||
|
|
|
@ -57,47 +57,46 @@ extension KeyHandler {
|
||||||
if readingCursorIndex + spanningLength <= compositor.cursor {
|
if readingCursorIndex + spanningLength <= compositor.cursor {
|
||||||
composedStringCursorIndex += strNodeValue.utf16.count
|
composedStringCursorIndex += strNodeValue.utf16.count
|
||||||
readingCursorIndex += spanningLength
|
readingCursorIndex += spanningLength
|
||||||
} else {
|
continue
|
||||||
if codepointCount == spanningLength {
|
}
|
||||||
var i = 0
|
if codepointCount == spanningLength {
|
||||||
while i < codepointCount, readingCursorIndex < compositor.cursor {
|
for i in 0..<codepointCount {
|
||||||
composedStringCursorIndex += arrSplit[i].utf16.count
|
guard readingCursorIndex < compositor.cursor else { continue }
|
||||||
readingCursorIndex += 1
|
composedStringCursorIndex += arrSplit[i].utf16.count
|
||||||
i += 1
|
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 {
|
} else {
|
||||||
if readingCursorIndex < compositor.cursor {
|
tooltipParameterRef[i] = Tekkon.cnvZhuyinChainToTextbookReading(target: tooltipParameterRef[i])
|
||||||
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])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,10 +125,9 @@ extension KeyHandler {
|
||||||
// 防止組字區內出現不可列印的字元。
|
// 防止組字區內出現不可列印的字元。
|
||||||
var cleanedComposition = ""
|
var cleanedComposition = ""
|
||||||
for theChar in composedText {
|
for theChar in composedText {
|
||||||
if let charCode = theChar.utf16.first {
|
guard let charCode = theChar.utf16.first else { continue }
|
||||||
if !(theChar.isASCII && !(charCode.isPrintable)) {
|
if !(theChar.isASCII && !(charCode.isPrintable)) {
|
||||||
cleanedComposition += String(theChar)
|
cleanedComposition += String(theChar)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue