KeyHandler // Fix an overkill error in consolidateCursorContext().

This commit is contained in:
ShikiSuen 2022-08-27 17:20:24 +08:00
parent 633d656144
commit 1927d1ca74
1 changed files with 20 additions and 21 deletions

View File

@ -142,38 +142,37 @@ public class KeyHandler {
///
/// v1.9.3 SP2 Bug v1.9.4
/// v2.0.2
/// - Parameters:
/// - theCandidate:
/// - cursorSpecified: actualCandidateCursor
func consolidateCursorContext(with theCandidate: Megrez.Compositor.Candidate = .init(), cursorSpecified: Int? = nil) {
var cursorSpecified = cursorSpecified ?? actualCandidateCursor
if cursorSpecified != actualCandidateCursor {
cursorSpecified = max(0, min(cursorSpecified, compositor.width - 1)) //
}
let grid = compositor
var frontBoundaryEX = compositor.width - 1
var rearBoundaryEX = 0
if grid.overrideCandidate(theCandidate, at: cursorSpecified) {
guard let node = compositor.walkedNodes.findNode(at: cursorSpecified, target: &frontBoundaryEX) else {
return
}
rearBoundaryEX = max(0, frontBoundaryEX - node.keyArray.count)
/// - Parameter theCandidate:
func consolidateCursorContext(with theCandidate: Megrez.Compositor.Candidate) {
var grid = compositor
var frontBoundaryEX = actualCandidateCursor + 1
var rearBoundaryEX = actualCandidateCursor
var debugIntelToPrint = ""
if grid.overrideCandidate(theCandidate, at: actualCandidateCursor) {
grid.walk()
let range = grid.walkedNodes.contextRange(ofGivenCursor: actualCandidateCursor)
rearBoundaryEX = range.lowerBound
frontBoundaryEX = range.upperBound
debugIntelToPrint.append("EX: \(rearBoundaryEX)..<\(frontBoundaryEX), ")
}
var frontBoundary = 0
guard let node = compositor.walkedNodes.findNode(at: cursorSpecified, target: &frontBoundary) else { return }
let range = compositor.walkedNodes.contextRange(ofGivenCursor: actualCandidateCursor)
var rearBoundary = min(range.lowerBound, rearBoundaryEX)
var frontBoundary = max(range.upperBound, frontBoundaryEX)
var rearBoundary = min(max(0, frontBoundary - node.keyArray.count), rearBoundaryEX) //
frontBoundary = max(min(frontBoundary, compositor.width), frontBoundaryEX) //
debugIntelToPrint.append("INI: \(rearBoundary)..<\(frontBoundary), ")
let cursorBackup = compositor.cursor
while compositor.cursor > rearBoundary { compositor.jumpCursorBySpan(to: .rear) }
rearBoundary = min(compositor.cursor, rearBoundary)
compositor.cursor = cursorBackup //
while compositor.cursor < frontBoundary { compositor.jumpCursorBySpan(to: .front) }
frontBoundary = max(compositor.cursor, frontBoundary)
frontBoundary = min(max(compositor.cursor, frontBoundary), compositor.width)
compositor.cursor = cursorBackup //
debugIntelToPrint.append("FIN: \(rearBoundary)..<\(frontBoundary)")
IME.prtDebugIntel(debugIntelToPrint)
//
var nodeIndices = [Int]() //