KeyHandler // Nomenclature Fix: Nodes -> Anchors.
This commit is contained in:
parent
fba6ff5d33
commit
5448d20936
|
@ -236,20 +236,20 @@ class KeyHandler {
|
||||||
|
|
||||||
/// 獲取候選字詞陣列資料內容。
|
/// 獲取候選字詞陣列資料內容。
|
||||||
func candidatesArray(fixOrder: Bool = true) -> [String] {
|
func candidatesArray(fixOrder: Bool = true) -> [String] {
|
||||||
var arrNodes: [Megrez.NodeAnchor] = rawNodes
|
var arrAnchors: [Megrez.NodeAnchor] = rawAnchorsOfNodes
|
||||||
var arrCandidates: [String] = []
|
var arrCandidates: [String] = []
|
||||||
|
|
||||||
/// 原理:nodes 這個回饋結果包含一堆子陣列,分別對應不同詞長的候選字。
|
/// 原理:nodes 這個回饋結果包含一堆子陣列,分別對應不同詞長的候選字。
|
||||||
/// 這裡先對陣列排序、讓最長候選字的子陣列的優先權最高。
|
/// 這裡先對陣列排序、讓最長候選字的子陣列的優先權最高。
|
||||||
/// 這個過程不會傷到子陣列內部的排序。
|
/// 這個過程不會傷到子陣列內部的排序。
|
||||||
if arrNodes.isEmpty { return arrCandidates }
|
if arrAnchors.isEmpty { return arrCandidates }
|
||||||
|
|
||||||
// sort the nodes, so that longer nodes (representing longer phrases)
|
// sort the nodes, so that longer nodes (representing longer phrases)
|
||||||
// are placed at the top of the candidate list
|
// are placed at the top of the candidate list
|
||||||
arrNodes = arrNodes.stableSort { $0.keyLength > $1.keyLength }
|
arrAnchors = arrAnchors.stableSort { $0.keyLength > $1.keyLength }
|
||||||
|
|
||||||
// then use the Swift trick to retrieve the candidates for each node at/crossing the cursor
|
// then use the Swift trick to retrieve the candidates for each node at/crossing the cursor
|
||||||
for currentNodeAnchor in arrNodes {
|
for currentNodeAnchor in arrAnchors {
|
||||||
if let currentNode = currentNodeAnchor.node {
|
if let currentNode = currentNodeAnchor.node {
|
||||||
for currentCandidate in currentNode.candidates {
|
for currentCandidate in currentNode.candidates {
|
||||||
// 選字窗的內容的康熙轉換 / JIS 轉換不能放在這裡處理,會影響選字有效性。
|
// 選字窗的內容的康熙轉換 / JIS 轉換不能放在這裡處理,會影響選字有效性。
|
||||||
|
@ -293,7 +293,7 @@ class KeyHandler {
|
||||||
compositor.grid.overrideNodeScoreForSelectedCandidate(
|
compositor.grid.overrideNodeScoreForSelectedCandidate(
|
||||||
location: min(actualCandidateCursorIndex + (mgrPrefs.useRearCursorMode ? 1 : 0), compositorLength),
|
location: min(actualCandidateCursorIndex + (mgrPrefs.useRearCursorMode ? 1 : 0), compositorLength),
|
||||||
value: overrideValue,
|
value: overrideValue,
|
||||||
overridingScore: findHighestScore(nodes: rawNodes, epsilon: kEpsilon)
|
overridingScore: findHighestScore(nodes: rawAnchorsOfNodes, epsilon: kEpsilon)
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
IME.prtDebugIntel("UOM: Blank suggestion retrieved, dismissing.")
|
IME.prtDebugIntel("UOM: Blank suggestion retrieved, dismissing.")
|
||||||
|
@ -402,7 +402,7 @@ class KeyHandler {
|
||||||
var isCompositorEmpty: Bool { compositor.isEmpty }
|
var isCompositorEmpty: Bool { compositor.isEmpty }
|
||||||
|
|
||||||
/// 獲取原始節錨資料陣列。
|
/// 獲取原始節錨資料陣列。
|
||||||
var rawNodes: [Megrez.NodeAnchor] {
|
var rawAnchorsOfNodes: [Megrez.NodeAnchor] {
|
||||||
/// 警告:不要對游標前置風格使用 nodesCrossing,否則會導致游標行為與 macOS 內建注音輸入法不一致。
|
/// 警告:不要對游標前置風格使用 nodesCrossing,否則會導致游標行為與 macOS 內建注音輸入法不一致。
|
||||||
/// 微軟新注音輸入法的游標後置風格也是不允許 nodeCrossing 的。
|
/// 微軟新注音輸入法的游標後置風格也是不允許 nodeCrossing 的。
|
||||||
mgrPrefs.useRearCursorMode
|
mgrPrefs.useRearCursorMode
|
||||||
|
|
|
@ -44,8 +44,8 @@ extension KeyHandler {
|
||||||
/// IMK 協定的內文組字區的游標長度與游標位置無法正確統計 UTF8 高萬字(比如 emoji)的長度,
|
/// IMK 協定的內文組字區的游標長度與游標位置無法正確統計 UTF8 高萬字(比如 emoji)的長度,
|
||||||
/// 所以在這裡必須做糾偏處理。因為在用 Swift,所以可以用「.utf16」取代「NSString.length()」。
|
/// 所以在這裡必須做糾偏處理。因為在用 Swift,所以可以用「.utf16」取代「NSString.length()」。
|
||||||
/// 這樣就可以免除不必要的類型轉換。
|
/// 這樣就可以免除不必要的類型轉換。
|
||||||
for walkedNode in walkedAnchors {
|
for theAnchor in walkedAnchors {
|
||||||
if let theNode = walkedNode.node {
|
if let theNode = theAnchor.node {
|
||||||
let strNodeValue = theNode.currentKeyValue.value
|
let strNodeValue = theNode.currentKeyValue.value
|
||||||
composingBuffer += strNodeValue
|
composingBuffer += strNodeValue
|
||||||
let arrSplit: [String] = Array(strNodeValue).map { String($0) }
|
let arrSplit: [String] = Array(strNodeValue).map { String($0) }
|
||||||
|
@ -53,7 +53,7 @@ extension KeyHandler {
|
||||||
/// 藉下述步驟重新將「可見游標位置」對齊至「組字器內的游標所在的讀音位置」。
|
/// 藉下述步驟重新將「可見游標位置」對齊至「組字器內的游標所在的讀音位置」。
|
||||||
/// 每個節錨(NodeAnchor)都有自身的幅位長度(spanningLength),可以用來
|
/// 每個節錨(NodeAnchor)都有自身的幅位長度(spanningLength),可以用來
|
||||||
/// 累加、以此為依據,來校正「可見游標位置」。
|
/// 累加、以此為依據,來校正「可見游標位置」。
|
||||||
let spanningLength: Int = walkedNode.spanningLength
|
let spanningLength: Int = theAnchor.spanningLength
|
||||||
if readingCursorIndex + spanningLength <= compositorCursorIndex {
|
if readingCursorIndex + spanningLength <= compositorCursorIndex {
|
||||||
composedStringCursorIndex += strNodeValue.utf16.count
|
composedStringCursorIndex += strNodeValue.utf16.count
|
||||||
readingCursorIndex += spanningLength
|
readingCursorIndex += spanningLength
|
||||||
|
|
Loading…
Reference in New Issue