KeyHandler // Implement Alt+Fwd/Bwd support.

This commit is contained in:
ShikiSuen 2022-07-09 10:24:15 +08:00
parent e681c2e31b
commit f8086500a0
2 changed files with 41 additions and 4 deletions

View File

@ -166,10 +166,10 @@ class KeyHandler {
/// - value:
/// - respectCursorPushing: true
func fixNode(value: String, respectCursorPushing: Bool = true) {
let cursorIndex = min(actualCandidateCursorIndex + (mgrPrefs.useRearCursorMode ? 1 : 0), compositorLength)
let adjustedIndex = max(0, min(actualCandidateCursorIndex + (mgrPrefs.useRearCursorMode ? 1 : 0), compositorLength))
//
let selectedNode: Megrez.NodeAnchor = compositor.grid.fixNodeSelectedCandidate(
location: cursorIndex, value: value
location: adjustedIndex, value: value
)
//
if !mgrPrefs.useSCPCTypingMode {
@ -193,7 +193,7 @@ class KeyHandler {
//
//
currentUOM.observe(
walkedAnchors: walkedAnchors, cursorIndex: cursorIndex, candidate: value,
walkedAnchors: walkedAnchors, cursorIndex: adjustedIndex, candidate: value,
timestamp: NSDate().timeIntervalSince1970
)
}
@ -206,7 +206,7 @@ class KeyHandler {
if mgrPrefs.moveCursorAfterSelectingCandidate, respectCursorPushing {
var nextPosition = 0
for theAnchor in walkedAnchors {
if nextPosition >= cursorIndex { break }
if nextPosition >= adjustedIndex { break }
nextPosition += theAnchor.spanningLength
}
if nextPosition <= compositorLength {
@ -452,4 +452,20 @@ class KeyHandler {
func deleteCompositorReadingToTheFrontOfCursor() {
compositor.deleteReadingToTheFrontOfCursor()
}
///
/// - Returns:
var keyLengthAtCurrentIndex: Int {
guard let node = walkedAnchors[compositorCursorIndex].node else { return 0 }
return node.key.split(separator: "-").count
}
var nextPhrasePosition: Int {
var nextPosition = 0
for theAnchor in walkedAnchors {
if nextPosition > actualCandidateCursorIndex { break }
nextPosition += theAnchor.spanningLength
}
return min(nextPosition, compositorLength)
}
}

View File

@ -651,6 +651,15 @@ extension KeyHandler {
errorCallback()
stateCallback(state)
}
} else if input.isOptionHold {
if compositorCursorIndex < compositorLength {
compositorCursorIndex = nextPhrasePosition
stateCallback(buildInputtingState)
} else {
IME.prtDebugIntel("33C3B580")
errorCallback()
stateCallback(state)
}
} else {
if compositorCursorIndex < compositorLength {
compositorCursorIndex += 1
@ -707,6 +716,18 @@ extension KeyHandler {
errorCallback()
stateCallback(state)
}
} else if input.isOptionHold {
if compositorCursorIndex > 1 {
compositorCursorIndex -= 2
stateCallback(buildInputtingState)
} else if compositorCursorIndex == 1 {
compositorCursorIndex = 0
stateCallback(buildInputtingState)
} else {
IME.prtDebugIntel("8D50DD9E")
errorCallback()
stateCallback(state)
}
} else {
if compositorCursorIndex > 0 {
compositorCursorIndex -= 1