KeyHandler // Implement Alt+Fwd/Bwd support.
This commit is contained in:
parent
e681c2e31b
commit
f8086500a0
|
@ -166,10 +166,10 @@ class KeyHandler {
|
||||||
/// - value: 給定之候選字字串。
|
/// - value: 給定之候選字字串。
|
||||||
/// - respectCursorPushing: 若該選項為 true,則會在選字之後始終將游標推送至選字厚的節錨的前方。
|
/// - respectCursorPushing: 若該選項為 true,則會在選字之後始終將游標推送至選字厚的節錨的前方。
|
||||||
func fixNode(value: String, respectCursorPushing: Bool = 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(
|
let selectedNode: Megrez.NodeAnchor = compositor.grid.fixNodeSelectedCandidate(
|
||||||
location: cursorIndex, value: value
|
location: adjustedIndex, value: value
|
||||||
)
|
)
|
||||||
// 不要針對逐字選字模式啟用臨時半衰記憶模型。
|
// 不要針對逐字選字模式啟用臨時半衰記憶模型。
|
||||||
if !mgrPrefs.useSCPCTypingMode {
|
if !mgrPrefs.useSCPCTypingMode {
|
||||||
|
@ -193,7 +193,7 @@ class KeyHandler {
|
||||||
// 令半衰記憶模組觀測給定的三元圖。
|
// 令半衰記憶模組觀測給定的三元圖。
|
||||||
// 這個過程會讓半衰引擎根據當前上下文生成三元圖索引鍵。
|
// 這個過程會讓半衰引擎根據當前上下文生成三元圖索引鍵。
|
||||||
currentUOM.observe(
|
currentUOM.observe(
|
||||||
walkedAnchors: walkedAnchors, cursorIndex: cursorIndex, candidate: value,
|
walkedAnchors: walkedAnchors, cursorIndex: adjustedIndex, candidate: value,
|
||||||
timestamp: NSDate().timeIntervalSince1970
|
timestamp: NSDate().timeIntervalSince1970
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -206,7 +206,7 @@ class KeyHandler {
|
||||||
if mgrPrefs.moveCursorAfterSelectingCandidate, respectCursorPushing {
|
if mgrPrefs.moveCursorAfterSelectingCandidate, respectCursorPushing {
|
||||||
var nextPosition = 0
|
var nextPosition = 0
|
||||||
for theAnchor in walkedAnchors {
|
for theAnchor in walkedAnchors {
|
||||||
if nextPosition >= cursorIndex { break }
|
if nextPosition >= adjustedIndex { break }
|
||||||
nextPosition += theAnchor.spanningLength
|
nextPosition += theAnchor.spanningLength
|
||||||
}
|
}
|
||||||
if nextPosition <= compositorLength {
|
if nextPosition <= compositorLength {
|
||||||
|
@ -452,4 +452,20 @@ class KeyHandler {
|
||||||
func deleteCompositorReadingToTheFrontOfCursor() {
|
func deleteCompositorReadingToTheFrontOfCursor() {
|
||||||
compositor.deleteReadingToTheFrontOfCursor()
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -651,6 +651,15 @@ extension KeyHandler {
|
||||||
errorCallback()
|
errorCallback()
|
||||||
stateCallback(state)
|
stateCallback(state)
|
||||||
}
|
}
|
||||||
|
} else if input.isOptionHold {
|
||||||
|
if compositorCursorIndex < compositorLength {
|
||||||
|
compositorCursorIndex = nextPhrasePosition
|
||||||
|
stateCallback(buildInputtingState)
|
||||||
|
} else {
|
||||||
|
IME.prtDebugIntel("33C3B580")
|
||||||
|
errorCallback()
|
||||||
|
stateCallback(state)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if compositorCursorIndex < compositorLength {
|
if compositorCursorIndex < compositorLength {
|
||||||
compositorCursorIndex += 1
|
compositorCursorIndex += 1
|
||||||
|
@ -707,6 +716,18 @@ extension KeyHandler {
|
||||||
errorCallback()
|
errorCallback()
|
||||||
stateCallback(state)
|
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 {
|
} else {
|
||||||
if compositorCursorIndex > 0 {
|
if compositorCursorIndex > 0 {
|
||||||
compositorCursorIndex -= 1
|
compositorCursorIndex -= 1
|
||||||
|
|
Loading…
Reference in New Issue