InputHandler // Accommodating Megrez 2.5.1 update.

- Utilizing [Node].smashedPairs, etc.
- Refactoring rotateCandidate().
This commit is contained in:
ShikiSuen 2022-12-15 14:49:03 +08:00
parent b75ab569b7
commit f9abcd4f09
2 changed files with 25 additions and 49 deletions

View File

@ -217,7 +217,7 @@ public class InputHandler: InputHandlerProtocol {
var position = rearBoundary //
while position < frontBoundary {
guard let regionIndex = compositor.cursorRegionMap[position] else {
guard let regionIndex = compositor.walkedNodes.cursorRegionMap[position] else {
position += 1
continue
}

View File

@ -342,32 +342,26 @@ extension InputHandler {
var composed = ""
for node in compositor.walkedNodes {
var key = node.keyArray.joined(separator: " ")
compositor.walkedNodes.smashedPairs.forEach { key, value in
var key = key
if !prefs.cassetteEnabled {
var keyArray = node.keyArray
for (i, neta) in keyArray.enumerated() {
keyArray[i] =
prefs.inlineDumpPinyinInLieuOfZhuyin
? Tekkon.restoreToneOneInPhona(target: neta) //
: Tekkon.cnvPhonaToTextbookReading(target: neta) //
}
key = keyArray.joined(separator: "\t")
key =
prefs.inlineDumpPinyinInLieuOfZhuyin
? Tekkon.restoreToneOneInPhona(target: key) //
: Tekkon.cnvPhonaToTextbookReading(target: key) //
if prefs.inlineDumpPinyinInLieuOfZhuyin {
key = Tekkon.cnvPhonaToHanyuPinyin(targetJoined: key) //
key = Tekkon.cnvHanyuPinyinToTextbookStyle(targetJoined: key) // 調
}
key = key.replacingOccurrences(of: "\t", with: " ")
}
let value = node.value
key = key.replacingOccurrences(of: "\t", with: " ")
if isShiftPressed {
if !composed.isEmpty { composed += " " }
composed += key
continue
composed += key.contains("_") ? "??" : key
return
}
//
@ -710,50 +704,32 @@ extension InputHandler {
return true
}
var length = 0
var currentNode: Megrez.Compositor.Node?
let cursorIndex = cursorForCandidate
for node in compositor.walkedNodes {
length += node.spanLength
if length > cursorIndex {
currentNode = node
break
}
}
guard let currentNode = currentNode else {
delegate.callError("F58DEA95")
guard let region = compositor.walkedNodes.cursorRegionMap[cursorForCandidate],
compositor.walkedNodes.count > region
else {
delegate.callError("1CE6FFBD")
return true
}
let currentNode = compositor.walkedNodes[region]
let currentPaired = (currentNode.keyArray, currentNode.value)
var currentIndex = 0
if !currentNode.isOverridden {
/// 使
/// 使
/// 2 使
///
///
/// 使
/// (Shift+)Tab ()
/// Shift(+Command)+Space Alt+/ Alt+/
/// Tab
if candidates[0] == currentPaired {
///
///
currentIndex = reverseOrder ? candidates.count - 1 : 1
}
} else {
var currentIndex: Int {
var result = 0
for candidate in candidates {
currentIndex =
if !currentNode.isOverridden {
if candidates[0] == currentPaired { result = reverseOrder ? candidates.count - 1 : 1 }
break
}
result =
(candidate == currentPaired && reverseOrder)
? ((currentIndex == 0) ? candidates.count - 1 : currentIndex - 1) : currentIndex + 1
? ((result == 0) ? candidates.count - 1 : result - 1) : result + 1
if candidate == currentPaired { break }
}
return (0..<candidates.count).contains(result) ? result : 0
}
if currentIndex >= candidates.count { currentIndex = 0 }
consolidateNode(
candidate: candidates[currentIndex], respectCursorPushing: false,
preConsolidate: false, skipObservation: true