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 = 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 {

View File

@ -57,16 +57,17 @@ 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 { if codepointCount == spanningLength {
var i = 0 for i in 0..<codepointCount {
while i < codepointCount, readingCursorIndex < compositor.cursor { guard readingCursorIndex < compositor.cursor else { continue }
composedStringCursorIndex += arrSplit[i].utf16.count composedStringCursorIndex += arrSplit[i].utf16.count
readingCursorIndex += 1 readingCursorIndex += 1
i += 1
} }
} else { continue
if readingCursorIndex < compositor.cursor { }
guard readingCursorIndex < compositor.cursor else { continue }
composedStringCursorIndex += strNodeValue.utf16.count composedStringCursorIndex += strNodeValue.utf16.count
readingCursorIndex += spanningLength readingCursorIndex += spanningLength
readingCursorIndex = min(readingCursorIndex, compositor.cursor) readingCursorIndex = min(readingCursorIndex, compositor.cursor)
@ -86,6 +87,7 @@ extension KeyHandler {
tooltipParameterRef[1] = compositor.readings[compositor.cursor] tooltipParameterRef[1] = compositor.readings[compositor.cursor]
} }
/// ///
guard tooltipParameterRef != ["", ""] else { continue }
for (i, _) in tooltipParameterRef.enumerated() { for (i, _) in tooltipParameterRef.enumerated() {
if tooltipParameterRef[i].isEmpty { continue } if tooltipParameterRef[i].isEmpty { continue }
if tooltipParameterRef[i].contains("_") { continue } if tooltipParameterRef[i].contains("_") { continue }
@ -98,9 +100,6 @@ extension KeyHandler {
} }
} }
} }
}
}
}
/// ///
/// 便 composer /// 便 composer
@ -126,12 +125,11 @@ 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)
} }
} }
}
/// 使 /// 使
let stateResult = InputState.Inputting(composingBuffer: cleanedComposition, cursorIndex: cursorIndex) let stateResult = InputState.Inputting(composingBuffer: cleanedComposition, cursorIndex: cursorIndex)