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 {
if let currentNode = currentNodeAnchor.node {
for currentCandidate in currentNode.candidates {
// / JIS
//
//
arrCandidates.append(currentCandidate.value)
}
guard let currentNode = currentNodeAnchor.node else { continue }
for currentCandidate in currentNode.candidates {
// / JIS
//
//
arrCandidates.append(currentCandidate.value)
}
}
// 調

View File

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