From 2c132a4f92c91c2da3b532105b4da1f492f4d20f Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Tue, 29 Aug 2023 00:11:49 +0800 Subject: [PATCH] Repo // Auto-expand candidate UI under certain conditions. --- .../CandidateWindow/TDKCandidates/CtlCandidateTDK.swift | 3 ++- .../Sources/MainAssembly/SessionCtl_Delegates.swift | 6 ++++++ .../Sources/Shared/Protocols/CtlCandidateProtocol.swift | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/CtlCandidateTDK.swift b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/CtlCandidateTDK.swift index 9d8c0ff5..14755e89 100644 --- a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/CtlCandidateTDK.swift +++ b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/CtlCandidateTDK.swift @@ -96,7 +96,8 @@ public class CtlCandidateTDK: CtlCandidate, NSWindowDelegate { CandidateCellData.unifiedSize = candidateFont.pointSize guard let delegate = delegate else { return } Self.thePool = .init( - candidates: delegate.candidatePairs(conv: true), lines: maxLinesPerPage, isExpanded: false, + candidates: delegate.candidatePairs(conv: true), lines: maxLinesPerPage, + isExpanded: delegate.shouldAutoExpandCandidates, selectionKeys: delegate.selectionKeys, layout: currentLayout.layoutTDK, locale: locale ) Self.thePool.tooltip = tooltip diff --git a/Packages/vChewing_MainAssembly/Sources/MainAssembly/SessionCtl_Delegates.swift b/Packages/vChewing_MainAssembly/Sources/MainAssembly/SessionCtl_Delegates.swift index 68d7c8ae..c8cb811d 100644 --- a/Packages/vChewing_MainAssembly/Sources/MainAssembly/SessionCtl_Delegates.swift +++ b/Packages/vChewing_MainAssembly/Sources/MainAssembly/SessionCtl_Delegates.swift @@ -79,6 +79,12 @@ extension SessionCtl: InputHandlerDelegate { extension SessionCtl: CtlCandidateDelegate { public var isCandidateState: Bool { state.isCandidateContainer } + + public var shouldAutoExpandCandidates: Bool { + guard state.type == .ofSymbolTable else { return state.type == .ofAssociates } + return state.node.previous != nil + } + public var isCandidateContextMenuEnabled: Bool { state.type == .ofCandidates && !clientBundleIdentifier.contains("com.apple.Spotlight") && !clientBundleIdentifier.contains("com.raycast.macos") diff --git a/Packages/vChewing_Shared/Sources/Shared/Protocols/CtlCandidateProtocol.swift b/Packages/vChewing_Shared/Sources/Shared/Protocols/CtlCandidateProtocol.swift index 6391891e..135c8188 100644 --- a/Packages/vChewing_Shared/Sources/Shared/Protocols/CtlCandidateProtocol.swift +++ b/Packages/vChewing_Shared/Sources/Shared/Protocols/CtlCandidateProtocol.swift @@ -19,6 +19,7 @@ public protocol CtlCandidateDelegate { var selectionKeys: String { get } var isVerticalTyping: Bool { get } var isCandidateState: Bool { get } + var shouldAutoExpandCandidates: Bool { get } var isCandidateContextMenuEnabled: Bool { get } var showReverseLookupResult: Bool { get } }