KeyHandler // Add fixNodeIfNecessary().

This commit is contained in:
ShikiSuen 2022-05-31 23:56:10 +08:00
parent ba4654f850
commit 48d21fd60e
2 changed files with 24 additions and 0 deletions

View File

@ -108,6 +108,27 @@ class KeyHandler {
// MARK: - Functions dealing with Megrez.
func fixNodeIfNecessary() {
let width = _builder.grid.width
if width > kMaxComposingBufferNeedsToWalkSize {
var index = 0
for anchor in _walkedNodes {
if index >= (width - kMaxComposingBufferNeedsToWalkSize) {
break
}
guard let node = anchor.node else { continue }
if node.score < node.kSelectedCandidateScore {
let candidate = node.currentKeyValue.value
_builder.grid.fixNodeSelectedCandidate(
location: index + anchor.spanningLength,
value: candidate
)
}
index += anchor.spanningLength
}
}
}
func walk() {
// Retrieve the most likely grid, i.e. a Maximum Likelihood Estimation
// of the best possible Mandarin characters given the input syllables,

View File

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