KeyHandler // Upgrade certain condition structures.
This commit is contained in:
parent
c68d7dd151
commit
02abb79668
|
@ -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 {
|
||||
|
|
|
@ -57,16 +57,17 @@ extension KeyHandler {
|
|||
if readingCursorIndex + spanningLength <= compositor.cursor {
|
||||
composedStringCursorIndex += strNodeValue.utf16.count
|
||||
readingCursorIndex += spanningLength
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
if codepointCount == spanningLength {
|
||||
var i = 0
|
||||
while i < codepointCount, readingCursorIndex < compositor.cursor {
|
||||
for i in 0..<codepointCount {
|
||||
guard readingCursorIndex < compositor.cursor else { continue }
|
||||
composedStringCursorIndex += arrSplit[i].utf16.count
|
||||
readingCursorIndex += 1
|
||||
i += 1
|
||||
}
|
||||
} else {
|
||||
if readingCursorIndex < compositor.cursor {
|
||||
continue
|
||||
}
|
||||
guard readingCursorIndex < compositor.cursor else { continue }
|
||||
composedStringCursorIndex += strNodeValue.utf16.count
|
||||
readingCursorIndex += spanningLength
|
||||
readingCursorIndex = min(readingCursorIndex, compositor.cursor)
|
||||
|
@ -86,6 +87,7 @@ extension KeyHandler {
|
|||
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 }
|
||||
|
@ -98,9 +100,6 @@ extension KeyHandler {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 再接下來,藉由已經計算成功的「可見游標位置」,咱們計算一下在這個游標之前與之後的
|
||||
/// 組字區內容,以便之後在這之間插入正在輸入的漢字讀音(藉由鐵恨 composer 注拼槽取得)。
|
||||
|
@ -126,12 +125,11 @@ extension KeyHandler {
|
|||
// 防止組字區內出現不可列印的字元。
|
||||
var cleanedComposition = ""
|
||||
for theChar in composedText {
|
||||
if let charCode = theChar.utf16.first {
|
||||
guard let charCode = theChar.utf16.first else { continue }
|
||||
if !(theChar.isASCII && !(charCode.isPrintable)) {
|
||||
cleanedComposition += String(theChar)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 這裡生成準備要拿來回呼的「正在輸入」狀態,但還不能立即使用,因為工具提示仍未完成。
|
||||
let stateResult = InputState.Inputting(composingBuffer: cleanedComposition, cursorIndex: cursorIndex)
|
||||
|
|
Loading…
Reference in New Issue