From 50cb3c710672125b33c0113ebe85a09e70e68896 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Mon, 25 Jul 2022 23:03:54 +0800 Subject: [PATCH] ctlIME // Make multi-char associates associable. --- .../ctlInputMethod_Delegates.swift | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Source/Modules/ControllerModules/ctlInputMethod_Delegates.swift b/Source/Modules/ControllerModules/ctlInputMethod_Delegates.swift index c930bffd..817176ce 100644 --- a/Source/Modules/ControllerModules/ctlInputMethod_Delegates.swift +++ b/Source/Modules/ControllerModules/ctlInputMethod_Delegates.swift @@ -120,6 +120,7 @@ extension ctlInputMethod: ctlCandidateDelegate { keyHandler.clear() let composingBuffer = inputting.composingBuffer handle(state: InputState.Committing(textToCommit: composingBuffer)) + // 此時是逐字選字模式,所以「selectedValue.1」是單個字、不用追加處理。 if mgrPrefs.associatedPhrasesEnabled, let associatePhrases = keyHandler.buildAssociatePhraseState( withPair: .init(key: selectedValue.0, value: selectedValue.1), @@ -139,16 +140,22 @@ extension ctlInputMethod: ctlCandidateDelegate { if let state = state as? InputState.AssociatedPhrases { let selectedValue = state.candidates[index] handle(state: InputState.Committing(textToCommit: selectedValue.1)) + // 此時是聯想詞選字模式,所以「selectedValue.1」必須只保留最後一個字。 + // 不然的話,一旦你選中了由多個字組成的聯想候選詞,則連續聯想會被打斷。 + guard let valueKept = selectedValue.1.last else { + handle(state: InputState.Empty()) + return + } if mgrPrefs.associatedPhrasesEnabled, let associatePhrases = keyHandler.buildAssociatePhraseState( - withPair: .init(key: selectedValue.0, value: selectedValue.1), + withPair: .init(key: selectedValue.0, value: String(valueKept)), isTypingVertical: state.isTypingVertical ), !associatePhrases.candidates.isEmpty { handle(state: associatePhrases) - } else { - handle(state: InputState.Empty()) + return } + handle(state: InputState.Empty()) } } }