KeyHandler // Nomenclature Fix: Nodes -> Anchors.

This commit is contained in:
ShikiSuen 2022-06-29 13:30:35 +08:00
parent fba6ff5d33
commit 5448d20936
2 changed files with 9 additions and 9 deletions

View File

@ -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

View File

@ -44,8 +44,8 @@ extension KeyHandler {
/// IMK UTF8 emoji /// IMK UTF8 emoji
/// Swift.utf16NSString.length() /// Swift.utf16NSString.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 {
/// ///
/// NodeAnchorspanningLength /// NodeAnchorspanningLength
/// ///
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