From 1c249d7818dfd5e5e44f48e45e52c9659e0c22af Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Mon, 19 Sep 2022 15:16:00 +0800 Subject: [PATCH] Repo // Reenable tooltip color sync. --- Source/Modules/ControllerModules/IMEStateData.swift | 12 +++++++----- .../ctlInputMethod_HandleDisplay.swift | 3 +++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Source/Modules/ControllerModules/IMEStateData.swift b/Source/Modules/ControllerModules/IMEStateData.swift index a96dc43e..096dbeee 100644 --- a/Source/Modules/ControllerModules/IMEStateData.swift +++ b/Source/Modules/ControllerModules/IMEStateData.swift @@ -86,6 +86,8 @@ public struct StateData { mgrPrefs.allowedMarkLengthRange.contains(markedRange.count) } + var tooltipColorState: ctlTooltip.ColorStates = .normal + var attributedStringNormal: NSAttributedString { /// 考慮到因為滑鼠點擊等其它行為導致的組字區內容遞交情況, /// 這裡對組字區內容也加上康熙字轉換或者 JIS 漢字轉換處理。 @@ -197,7 +199,7 @@ extension StateData { public static func updateParameters(_ data: inout StateData) { var tooltipGenerated: String { if mgrPrefs.phraseReplacementEnabled { - ctlInputMethod.tooltipInstance.setColor(state: .warning) + data.tooltipColorState = .warning return NSLocalizedString( "⚠︎ Phrase replacement mode enabled, interfering user phrase entry.", comment: "" ) @@ -208,14 +210,14 @@ extension StateData { let text = data.displayedText.charComponents[data.markedRange].joined() if data.markedRange.count < mgrPrefs.allowedMarkLengthRange.lowerBound { - ctlInputMethod.tooltipInstance.setColor(state: .denialInsufficiency) + data.tooltipColorState = .denialInsufficiency return String( format: NSLocalizedString( "\"%@\" length must ≥ 2 for a user phrase.", comment: "" ) + "\n◆ " + generateReadingThread(data), text ) } else if data.markedRange.count > mgrPrefs.allowedMarkLengthRange.upperBound { - ctlInputMethod.tooltipInstance.setColor(state: .denialOverflow) + data.tooltipColorState = .denialOverflow return String( format: NSLocalizedString( "\"%@\" length should ≤ %d for a user phrase.", comment: "" @@ -229,7 +231,7 @@ extension StateData { ) if exist { data.markedTargetExists = exist - ctlInputMethod.tooltipInstance.setColor(state: .prompt) + data.tooltipColorState = .prompt return String( format: NSLocalizedString( "\"%@\" already exists:\n ENTER to boost, SHIFT+COMMAND+ENTER to nerf, \n BackSpace or Delete key to exclude.", @@ -237,7 +239,7 @@ extension StateData { ) + "\n◆ " + generateReadingThread(data), text ) } - ctlInputMethod.tooltipInstance.resetColor() + data.tooltipColorState = .normal return String( format: NSLocalizedString("\"%@\" selected. ENTER to add user phrase.", comment: "") + "\n◆ " + generateReadingThread(data), diff --git a/Source/Modules/ControllerModules/ctlInputMethod_HandleDisplay.swift b/Source/Modules/ControllerModules/ctlInputMethod_HandleDisplay.swift index 77946bad..32457db4 100644 --- a/Source/Modules/ControllerModules/ctlInputMethod_HandleDisplay.swift +++ b/Source/Modules/ControllerModules/ctlInputMethod_HandleDisplay.swift @@ -62,6 +62,9 @@ extension ctlInputMethod { do { ctlInputMethod.tooltipInstance.hide() ctlInputMethod.tooltipInstance = .init() + if state.type == .ofMarking { + ctlInputMethod.tooltipInstance.setColor(state: state.data.tooltipColorState) + } } // 再設定其文字顯示內容並顯示。 ctlInputMethod.tooltipInstance.show(