From 48d21fd60e727ee57ac0f7d9e39fd2681d9a588b Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Tue, 31 May 2022 23:56:10 +0800 Subject: [PATCH] KeyHandler // Add fixNodeIfNecessary(). --- .../ControllerModules/KeyHandler_Core.swift | 21 +++++++++++++++++++ .../KeyHandler_HandleInput.swift | 3 +++ 2 files changed, 24 insertions(+) diff --git a/Source/Modules/ControllerModules/KeyHandler_Core.swift b/Source/Modules/ControllerModules/KeyHandler_Core.swift index a12349a5..c063ee1d 100644 --- a/Source/Modules/ControllerModules/KeyHandler_Core.swift +++ b/Source/Modules/ControllerModules/KeyHandler_Core.swift @@ -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, diff --git a/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift b/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift index acb9633f..19e36b32 100644 --- a/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift +++ b/Source/Modules/ControllerModules/KeyHandler_HandleInput.swift @@ -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()