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,17 +239,17 @@ class KeyHandler {
///
var candidatesArray: [String] {
var arrNodes: [Megrez.NodeAnchor] = rawNodes
var arrCandidates: [String] = []
var arrNodes: [Megrez.NodeAnchor] = []
arrNodes.append(contentsOf: rawNodes)
/// 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 }
arrNodes = arrNodes.stableSort { $0.keyLength > $1.keyLength }
// then use the Swift trick to retrieve the candidates for each node at/crossing the cursor
for currentNodeAnchor in arrNodes {
@ -262,6 +262,12 @@ class KeyHandler {
}
}
}
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
}