From 3cc7972613e265827474fd4dd961dc9842a5a24c Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Wed, 30 Nov 2022 21:58:50 +0800 Subject: [PATCH] InputHandler // Add updateUnigramData(). --- Source/Modules/InputHandler_Core.swift | 8 ++++++++ Source/Modules/SessionCtl_Delegates.swift | 6 ++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Source/Modules/InputHandler_Core.swift b/Source/Modules/InputHandler_Core.swift index 1d425f7b..90cb7f1d 100644 --- a/Source/Modules/InputHandler_Core.swift +++ b/Source/Modules/InputHandler_Core.swift @@ -32,6 +32,7 @@ public protocol InputHandlerProtocol { func generateStateOfInputting(sansReading: Bool) -> IMEStateProtocol func generateStateOfAssociates(withPair pair: Megrez.Compositor.KeyValuePaired) -> IMEStateProtocol func consolidateNode(candidate: (String, String), respectCursorPushing: Bool, preConsolidate: Bool) + func updateUnigramData() -> Bool } extension InputHandlerProtocol { @@ -436,6 +437,13 @@ public class InputHandler: InputHandlerProtocol { // MARK: - Extracted methods and functions (Megrez). + /// 就地增刪詞之後,需要就地更新游標上下文單元圖資料。 + public func updateUnigramData() -> Bool { + let result = compositor.update(updateExisting: true) + defer { walk() } + return result > 0 + } + /// 生成標點符號索引鍵。 /// - Parameter input: 輸入的按鍵訊號。 /// - Returns: 生成的標點符號索引鍵。 diff --git a/Source/Modules/SessionCtl_Delegates.swift b/Source/Modules/SessionCtl_Delegates.swift index 353f8167..af7b6fed 100644 --- a/Source/Modules/SessionCtl_Delegates.swift +++ b/Source/Modules/SessionCtl_Delegates.swift @@ -156,7 +156,7 @@ extension SessionCtl: CtlCandidateDelegate { } public func candidatePairRightClicked(at index: Int, action: CandidateContextMenuAction) { - guard isCandidateContextMenuEnabled else { return } + guard let inputHandler = inputHandler, isCandidateContextMenuEnabled else { return } var succeeded = true let rawPair = state.candidates[index] @@ -185,9 +185,11 @@ extension SessionCtl: CtlCandidateDelegate { // 開始針對使用者半衰模組的清詞處理 LMMgr.bleachSpecifiedSuggestions(targets: [valueCurrent], mode: IMEApp.currentInputMode) LMMgr.bleachSpecifiedSuggestions(targets: [valueReversed], mode: IMEApp.currentInputMode.reversed) + // 更新組字器內的單元圖資料。 + let updateResult = inputHandler.updateUnigramData(key: rawPair.0) // 清詞完畢 - var newState = IMEState.ofCommitting(textToCommit: state.displayedText) + var newState = inputHandler.generateStateOfInputting() newState.tooltipDuration = 1.85 var tooltipMessage = "" switch action {