KeyHandler // +markNodesFixedIfNecessary().

This commit is contained in:
ShikiSuen 2022-06-16 19:54:05 +08:00
parent b488e5bb4f
commit f486615194
2 changed files with 21 additions and 1 deletions

View File

@ -42,7 +42,7 @@ protocol KeyHandlerDelegate {
class KeyHandler {
let kEpsilon: Double = 0.000001
let kMaxComposingBufferNeedsToWalkSize: Int = 10
let kMaxComposingBufferNeedsToWalkSize = Int(max(12, ceil(Double(mgrPrefs.composingBufferSize) / 2)))
var composer: Tekkon.Composer = .init()
var compositor: Megrez.Compositor
var currentLM: vChewing.LMInstantiator = .init()
@ -188,6 +188,23 @@ class KeyHandler {
}
}
func markNodesFixedIfNecessary() {
let width = compositor.grid.width
if width <= kMaxComposingBufferNeedsToWalkSize {
return
}
var index: Int = 0
for anchor in walkedAnchors {
guard let node = anchor.node else { break }
if index >= width - kMaxComposingBufferNeedsToWalkSize { break }
if node.score < node.kSelectedCandidateScore {
compositor.grid.fixNodeSelectedCandidate(
location: index + anchor.spanningLength, value: node.currentKeyValue.value)
}
index += anchor.spanningLength
}
}
var candidatesArray: [String] {
var arrCandidates: [String] = []
var arrNodes: [Megrez.NodeAnchor] = []

View File

@ -190,6 +190,9 @@ extension KeyHandler {
// ... get and tweak override model suggestion if possible...
// dealWithOverrideModelSuggestions() // 使
// ... fix nodes if necessary...
markNodesFixedIfNecessary()
// ... then update the text.
composer.clear()