KeyHandler // Implementing MS-New-Phonetic style rear-cursor mode.
This commit is contained in:
parent
13d2569919
commit
dd70417aab
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue