InputHandler // Add updateUnigramData().

This commit is contained in:
ShikiSuen 2022-11-30 21:58:50 +08:00
parent 9028c6a5dd
commit 3cc7972613
2 changed files with 12 additions and 2 deletions

View File

@ -32,6 +32,7 @@ public protocol InputHandlerProtocol {
func generateStateOfInputting(sansReading: Bool) -> IMEStateProtocol func generateStateOfInputting(sansReading: Bool) -> IMEStateProtocol
func generateStateOfAssociates(withPair pair: Megrez.Compositor.KeyValuePaired) -> IMEStateProtocol func generateStateOfAssociates(withPair pair: Megrez.Compositor.KeyValuePaired) -> IMEStateProtocol
func consolidateNode(candidate: (String, String), respectCursorPushing: Bool, preConsolidate: Bool) func consolidateNode(candidate: (String, String), respectCursorPushing: Bool, preConsolidate: Bool)
func updateUnigramData() -> Bool
} }
extension InputHandlerProtocol { extension InputHandlerProtocol {
@ -436,6 +437,13 @@ public class InputHandler: InputHandlerProtocol {
// MARK: - Extracted methods and functions (Megrez). // MARK: - Extracted methods and functions (Megrez).
///
public func updateUnigramData() -> Bool {
let result = compositor.update(updateExisting: true)
defer { walk() }
return result > 0
}
/// ///
/// - Parameter input: /// - Parameter input:
/// - Returns: /// - Returns:

View File

@ -156,7 +156,7 @@ extension SessionCtl: CtlCandidateDelegate {
} }
public func candidatePairRightClicked(at index: Int, action: CandidateContextMenuAction) { public func candidatePairRightClicked(at index: Int, action: CandidateContextMenuAction) {
guard isCandidateContextMenuEnabled else { return } guard let inputHandler = inputHandler, isCandidateContextMenuEnabled else { return }
var succeeded = true var succeeded = true
let rawPair = state.candidates[index] let rawPair = state.candidates[index]
@ -185,9 +185,11 @@ extension SessionCtl: CtlCandidateDelegate {
// 使 // 使
LMMgr.bleachSpecifiedSuggestions(targets: [valueCurrent], mode: IMEApp.currentInputMode) LMMgr.bleachSpecifiedSuggestions(targets: [valueCurrent], mode: IMEApp.currentInputMode)
LMMgr.bleachSpecifiedSuggestions(targets: [valueReversed], mode: IMEApp.currentInputMode.reversed) 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 newState.tooltipDuration = 1.85
var tooltipMessage = "" var tooltipMessage = ""
switch action { switch action {