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 // var position = rearBoundary //
while position < frontBoundary { while position < frontBoundary {
guard let regionIndex = compositor.cursorRegionMap[position] else { guard let regionIndex = compositor.walkedNodes.cursorRegionMap[position] else {
position += 1 position += 1
continue continue
} }

View File

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