KeyHandler // Implementing MS-New-Phonetic style rear-cursor mode.

This commit is contained in:
ShikiSuen 2022-05-31 12:43:52 +08:00
parent 13d2569919
commit dd70417aab
3 changed files with 29 additions and 19 deletions

View File

@ -161,7 +161,7 @@ class KeyHandler {
}
func fixNode(value: String, respectCursorPushing: Bool = true) {
let cursorIndex: Int = actualCandidateCursorIndex
let cursorIndex = min(actualCandidateCursorIndex + (mgrPrefs.setRearCursorMode ? 1 : 0), builderLength)
let selectedNode: Megrez.NodeAnchor = _builder.grid.fixNodeSelectedCandidate(
location: cursorIndex, value: value
)
@ -244,7 +244,7 @@ class KeyHandler {
IME.prtDebugIntel(
"UOM: Suggestion retrieved, overriding the node score of the selected candidate.")
_builder.grid.overrideNodeScoreForSelectedCandidate(
location: actualCandidateCursorIndex,
location: min(actualCandidateCursorIndex + (mgrPrefs.setRearCursorMode ? 1 : 0), builderLength),
value: overrideValue,
overridingScore: findHighestScore(nodes: rawNodes, epsilon: kEpsilon)
)
@ -309,10 +309,9 @@ class KeyHandler {
var rawNodes: [Megrez.NodeAnchor] {
/// 使 nodesCrossing macOS
/// nodeCrossing Megrez
/// Windows
/// nodeCrossing
mgrPrefs.setRearCursorMode
? _builder.grid.nodesCrossingOrEndingAt(location: actualCandidateCursorIndex)
? _builder.grid.nodesBeginningAt(location: actualCandidateCursorIndex)
: _builder.grid.nodesEndingAt(location: actualCandidateCursorIndex)
}

View File

@ -35,19 +35,27 @@ extension KeyHandler {
var actualCandidateCursorIndex: Int {
var cursorIndex = builderCursorIndex
// Windows Yahoo Kimo IME style, phrase is *at the rear of* the cursor.
// (i.e. the cursor is always *before* the phrase.)
// This is different from MS Phonetics IME style ...
// ... since Windows Yahoo Kimo allows "node crossing".
if (mgrPrefs.setRearCursorMode
&& (cursorIndex < builderLength))
|| cursorIndex == 0
{
if cursorIndex == 0, !mgrPrefs.setRearCursorMode {
cursorIndex += keyLengthAtIndexZero
} else {
cursorIndex += 1
}
switch mgrPrefs.setRearCursorMode {
case false:
do {
// macOS built-in Zhuyin style.
// (i.e. the cursor is always in front of the phrase.)
// No crossing.
switch cursorIndex {
case 0: cursorIndex = 1
default: break
}
}
case true:
do {
// Microsoft new phonetics style.
// (i.e. the cursor is always at the rear of the phrase.)
// No crossing.
switch cursorIndex {
case builderLength: cursorIndex -= 1
default: break
}
}
}
return cursorIndex
}

View File

@ -625,9 +625,12 @@ extension KeyHandler {
var length = 0
var currentAnchor = Megrez.NodeAnchor()
let cursorIndex = min(
actualCandidateCursorIndex + (mgrPrefs.useRearCursorMode ? 1 : 0), builderLength
)
for anchor in _walkedNodes {
length += anchor.spanningLength
if length >= actualCandidateCursorIndex {
if length >= cursorIndex {
currentAnchor = anchor
break
}