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) {
|
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(
|
let selectedNode: Megrez.NodeAnchor = _builder.grid.fixNodeSelectedCandidate(
|
||||||
location: cursorIndex, value: value
|
location: cursorIndex, value: value
|
||||||
)
|
)
|
||||||
|
@ -244,7 +244,7 @@ class KeyHandler {
|
||||||
IME.prtDebugIntel(
|
IME.prtDebugIntel(
|
||||||
"UOM: Suggestion retrieved, overriding the node score of the selected candidate.")
|
"UOM: Suggestion retrieved, overriding the node score of the selected candidate.")
|
||||||
_builder.grid.overrideNodeScoreForSelectedCandidate(
|
_builder.grid.overrideNodeScoreForSelectedCandidate(
|
||||||
location: actualCandidateCursorIndex,
|
location: min(actualCandidateCursorIndex + (mgrPrefs.setRearCursorMode ? 1 : 0), builderLength),
|
||||||
value: overrideValue,
|
value: overrideValue,
|
||||||
overridingScore: findHighestScore(nodes: rawNodes, epsilon: kEpsilon)
|
overridingScore: findHighestScore(nodes: rawNodes, epsilon: kEpsilon)
|
||||||
)
|
)
|
||||||
|
@ -309,10 +309,9 @@ class KeyHandler {
|
||||||
|
|
||||||
var rawNodes: [Megrez.NodeAnchor] {
|
var rawNodes: [Megrez.NodeAnchor] {
|
||||||
/// 警告:不要對游標前置風格使用 nodesCrossing,否則會導致游標行為與 macOS 內建注音輸入法不一致。
|
/// 警告:不要對游標前置風格使用 nodesCrossing,否則會導致游標行為與 macOS 內建注音輸入法不一致。
|
||||||
/// 微軟新注音輸入法的游標後置風格也是不允許 nodeCrossing 的,但目前 Megrez 暫時缺乏對該特性的支援。
|
/// 微軟新注音輸入法的游標後置風格也是不允許 nodeCrossing 的。
|
||||||
/// 所以暫時只能將威注音的游標後置風格描述成「跟 Windows 版雅虎奇摩注音一致」。
|
|
||||||
mgrPrefs.setRearCursorMode
|
mgrPrefs.setRearCursorMode
|
||||||
? _builder.grid.nodesCrossingOrEndingAt(location: actualCandidateCursorIndex)
|
? _builder.grid.nodesBeginningAt(location: actualCandidateCursorIndex)
|
||||||
: _builder.grid.nodesEndingAt(location: actualCandidateCursorIndex)
|
: _builder.grid.nodesEndingAt(location: actualCandidateCursorIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,19 +35,27 @@ extension KeyHandler {
|
||||||
|
|
||||||
var actualCandidateCursorIndex: Int {
|
var actualCandidateCursorIndex: Int {
|
||||||
var cursorIndex = builderCursorIndex
|
var cursorIndex = builderCursorIndex
|
||||||
// Windows Yahoo Kimo IME style, phrase is *at the rear of* the cursor.
|
switch mgrPrefs.setRearCursorMode {
|
||||||
// (i.e. the cursor is always *before* the phrase.)
|
case false:
|
||||||
// This is different from MS Phonetics IME style ...
|
do {
|
||||||
// ... since Windows Yahoo Kimo allows "node crossing".
|
// macOS built-in Zhuyin style.
|
||||||
if (mgrPrefs.setRearCursorMode
|
// (i.e. the cursor is always in front of the phrase.)
|
||||||
&& (cursorIndex < builderLength))
|
// No crossing.
|
||||||
|| cursorIndex == 0
|
switch cursorIndex {
|
||||||
{
|
case 0: cursorIndex = 1
|
||||||
if cursorIndex == 0, !mgrPrefs.setRearCursorMode {
|
default: break
|
||||||
cursorIndex += keyLengthAtIndexZero
|
}
|
||||||
} else {
|
}
|
||||||
cursorIndex += 1
|
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
|
return cursorIndex
|
||||||
}
|
}
|
||||||
|
|
|
@ -625,9 +625,12 @@ extension KeyHandler {
|
||||||
|
|
||||||
var length = 0
|
var length = 0
|
||||||
var currentAnchor = Megrez.NodeAnchor()
|
var currentAnchor = Megrez.NodeAnchor()
|
||||||
|
let cursorIndex = min(
|
||||||
|
actualCandidateCursorIndex + (mgrPrefs.useRearCursorMode ? 1 : 0), builderLength
|
||||||
|
)
|
||||||
for anchor in _walkedNodes {
|
for anchor in _walkedNodes {
|
||||||
length += anchor.spanningLength
|
length += anchor.spanningLength
|
||||||
if length >= actualCandidateCursorIndex {
|
if length >= cursorIndex {
|
||||||
currentAnchor = anchor
|
currentAnchor = anchor
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue