KeyHandler // Use guard-let instead in some functions.

This commit is contained in:
ShikiSuen 2022-06-29 13:38:28 +08:00
parent f768d6c603
commit f4894e5828
2 changed files with 44 additions and 46 deletions

View File

@ -249,13 +249,12 @@ class KeyHandler {
// //
for currentNodeAnchor in arrAnchors { for currentNodeAnchor in arrAnchors {
if let currentNode = currentNodeAnchor.node { guard let currentNode = currentNodeAnchor.node else { continue }
for currentCandidate in currentNode.candidates { for currentCandidate in currentNode.candidates {
// / JIS // / JIS
// //
// //
arrCandidates.append(currentCandidate.value) arrCandidates.append(currentCandidate.value)
}
} }
} }
// 調 // 調

View File

@ -45,47 +45,46 @@ extension KeyHandler {
/// Swift.utf16NSString.length() /// Swift.utf16NSString.length()
/// ///
for theAnchor in walkedAnchors { for theAnchor in walkedAnchors {
if let theNode = theAnchor.node { guard let theNode = theAnchor.node else { continue }
let strNodeValue = theNode.currentKeyValue.value let strNodeValue = theNode.currentKeyValue.value
composingBuffer += strNodeValue composingBuffer += strNodeValue
let arrSplit: [String] = Array(strNodeValue).map { String($0) } let arrSplit: [String] = Array(strNodeValue).map { String($0) }
let codepointCount = arrSplit.count let codepointCount = arrSplit.count
/// ///
/// NodeAnchorspanningLength /// NodeAnchorspanningLength
/// ///
let spanningLength: Int = theAnchor.spanningLength let spanningLength: Int = theAnchor.spanningLength
if readingCursorIndex + spanningLength <= compositorCursorIndex { if readingCursorIndex + spanningLength <= compositorCursorIndex {
composedStringCursorIndex += strNodeValue.utf16.count composedStringCursorIndex += strNodeValue.utf16.count
readingCursorIndex += spanningLength readingCursorIndex += spanningLength
} else {
if codepointCount == spanningLength {
var i = 0
while i < codepointCount, readingCursorIndex < compositorCursorIndex {
composedStringCursorIndex += arrSplit[i].utf16.count
readingCursorIndex += 1
i += 1
}
} else { } else {
if codepointCount == spanningLength { if readingCursorIndex < compositorCursorIndex {
var i = 0 composedStringCursorIndex += strNodeValue.utf16.count
while i < codepointCount, readingCursorIndex < compositorCursorIndex { readingCursorIndex += spanningLength
composedStringCursorIndex += arrSplit[i].utf16.count readingCursorIndex = min(readingCursorIndex, compositorCursorIndex)
readingCursorIndex += 1 ///
i += 1 ///
} ///
} else { ///
if readingCursorIndex < compositorCursorIndex { ///
composedStringCursorIndex += strNodeValue.utf16.count switch compositorCursorIndex {
readingCursorIndex += spanningLength case compositor.readings.count...:
readingCursorIndex = min(readingCursorIndex, compositorCursorIndex) tooltipParameterRef[0] = compositor.readings[compositor.readings.count - 1]
/// case 0:
/// tooltipParameterRef[1] = compositor.readings[compositorCursorIndex]
/// default:
/// do {
/// tooltipParameterRef[0] = compositor.readings[compositorCursorIndex - 1]
switch compositorCursorIndex {
case compositor.readings.count...:
tooltipParameterRef[0] = compositor.readings[compositor.readings.count - 1]
case 0:
tooltipParameterRef[1] = compositor.readings[compositorCursorIndex] tooltipParameterRef[1] = compositor.readings[compositorCursorIndex]
default: }
do {
tooltipParameterRef[0] = compositor.readings[compositorCursorIndex - 1]
tooltipParameterRef[1] = compositor.readings[compositorCursorIndex]
}
}
} }
} }
} }