KeyHandler // Put UOM suggestions into candidate array.

This commit is contained in:
ShikiSuen 2022-06-22 17:17:14 +08:00
parent 00ca43ca52
commit 786bff189b
1 changed files with 21 additions and 15 deletions

View File

@ -239,30 +239,36 @@ class KeyHandler {
/// ///
var candidatesArray: [String] { var candidatesArray: [String] {
var arrNodes: [Megrez.NodeAnchor] = rawNodes
var arrCandidates: [String] = [] var arrCandidates: [String] = []
var arrNodes: [Megrez.NodeAnchor] = []
arrNodes.append(contentsOf: rawNodes)
/// nodes /// nodes
/// ///
/// ///
if !arrNodes.isEmpty { if arrNodes.isEmpty { return arrCandidates }
// sort the nodes, so that longer nodes (representing longer phrases)
// are placed at the top of the candidate list
arrNodes.sort { $0.keyLength > $1.keyLength }
// then use the Swift trick to retrieve the candidates for each node at/crossing the cursor // sort the nodes, so that longer nodes (representing longer phrases)
for currentNodeAnchor in arrNodes { // are placed at the top of the candidate list
if let currentNode = currentNodeAnchor.node { arrNodes = arrNodes.stableSort { $0.keyLength > $1.keyLength }
for currentCandidate in currentNode.candidates {
// / JIS // then use the Swift trick to retrieve the candidates for each node at/crossing the cursor
// for currentNodeAnchor in arrNodes {
// if let currentNode = currentNodeAnchor.node {
arrCandidates.append(currentCandidate.value) for currentCandidate in currentNode.candidates {
} // / JIS
//
//
arrCandidates.append(currentCandidate.value)
} }
} }
} }
if mgrPrefs.fetchSuggestionsFromUserOverrideModel, !mgrPrefs.useSCPCTypingMode {
let arrSuggestedUnigrams: [Megrez.Unigram] = fetchSuggestedCandidates().stableSort { $0.score > $1.score }
let arrSuggestedCandidates: [String] = arrSuggestedUnigrams.map { $0.keyValue.value }
arrCandidates = arrSuggestedCandidates.filter { arrCandidates.contains($0) } + arrCandidates
arrCandidates = arrCandidates.deduplicate
arrCandidates = arrCandidates.stableSort { $0.count > $1.count }
}
return arrCandidates return arrCandidates
} }