diff --git a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/CandidateCellData_Core.swift b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/CandidateCellData_Core.swift index 9de09970..a9be9ddb 100644 --- a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/CandidateCellData_Core.swift +++ b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/CandidateCellData_Core.swift @@ -200,14 +200,14 @@ public class CandidateCellData: Hashable { return attrStrCandidate } - public var charDescriptions: [String] { + public func charDescriptions(shortened: Bool = false) -> [String] { var result = displayedText if displayedText.contains("("), displayedText.count > 2 { result = displayedText.replacingOccurrences(of: "(", with: "").replacingOccurrences(of: ")", with: "") } return result.flatMap(\.unicodeScalars).compactMap { let theName: String = $0.properties.name ?? "" - return String(format: "U+%02X %@", $0.value, theName) + return shortened ? String(format: "U+%02X", $0.value) : String(format: "U+%02X %@", $0.value, theName) } } diff --git a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/CandidatePool_CocoaImpl.swift b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/CandidatePool_CocoaImpl.swift index 5c3ba073..5afe0650 100644 --- a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/CandidatePool_CocoaImpl.swift +++ b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/CandidatePool_CocoaImpl.swift @@ -301,10 +301,12 @@ extension CandidatePool { .font: Self.blankCell.phraseFont(size: reverseLookupTextSize), ] let result = NSMutableAttributedString(string: "", attributes: attrReverseLookupSpacer) + var addedCounter = 0 for neta in reverseLookupResult { result.append(NSAttributedString(string: " ", attributes: attrReverseLookupSpacer)) result.append(NSAttributedString(string: " \(neta) ", attributes: attrReverseLookup)) - if maxLinesPerPage == 1 { break } + addedCounter += 1 + if maxLinesPerPage == 1, addedCounter == 2 { break } } return result } diff --git a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/CtlCandidateTDK.swift b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/CtlCandidateTDK.swift index dfbc7e77..ad86f1e8 100644 --- a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/CtlCandidateTDK.swift +++ b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/TDKCandidates/CtlCandidateTDK.swift @@ -108,16 +108,30 @@ public class CtlCandidateTDK: CtlCandidate, NSWindowDelegate { override open func updateDisplay() { guard let window = window else { return } - if let currentCandidateText = Self.thePool.currentSelectedCandidateText { - reverseLookupResult = delegate?.reverseLookup(for: currentCandidateText) ?? [] - Self.thePool.reverseLookupResult = reverseLookupResult - Self.thePool.tooltip = delegate?.candidateToolTip(shortened: !Self.thePool.isMatrix) ?? "" - } - delegate?.candidatePairHighlightChanged(at: highlightedIndex) DispatchQueue.main.async { [weak self] in guard let self = self else { return } self.updateNSWindowModern(window) } + if let currentCandidate = Self.thePool.currentCandidate { + let displayedText = currentCandidate.displayedText + var lookupResult: [String?] = delegate?.reverseLookup(for: displayedText) ?? [] + if displayedText.count == 1, delegate?.showCodePointForCurrentCandidate ?? false { + if lookupResult.isEmpty { + lookupResult.append(currentCandidate.charDescriptions(shortened: !Self.thePool.isMatrix).first) + } else { + lookupResult.insert(currentCandidate.charDescriptions(shortened: true).first, at: lookupResult.startIndex) + } + reverseLookupResult = lookupResult.compactMap { $0 } + } else { + // 如果不提供 UNICODE 碼位資料顯示的話,則在非多行多列模式下僅顯示一筆反查資料。 + if !Self.thePool.isMatrix { + reverseLookupResult = [lookupResult.compactMap { $0 }.first].compactMap { $0 } + } + } + Self.thePool.reverseLookupResult = reverseLookupResult + } + Self.thePool.tooltip = delegate?.candidateToolTip(shortened: !Self.thePool.isMatrix) ?? "" + delegate?.candidatePairHighlightChanged(at: highlightedIndex) } func updateNSWindowModern(_ window: NSWindow) { diff --git a/Packages/vChewing_MainAssembly/Sources/MainAssembly/SessionController/SessionCtl_Delegates.swift b/Packages/vChewing_MainAssembly/Sources/MainAssembly/SessionController/SessionCtl_Delegates.swift index c3080e23..3e4570f9 100644 --- a/Packages/vChewing_MainAssembly/Sources/MainAssembly/SessionController/SessionCtl_Delegates.swift +++ b/Packages/vChewing_MainAssembly/Sources/MainAssembly/SessionController/SessionCtl_Delegates.swift @@ -80,6 +80,7 @@ extension SessionCtl: InputHandlerDelegate { extension SessionCtl: CtlCandidateDelegate { public var isCandidateState: Bool { state.isCandidateContainer } + public var showCodePointForCurrentCandidate: Bool { PrefMgr.shared.showCodePointInCandidateUI } public var clientAccentColor: NSColor? { var nullResponse = !PrefMgr.shared.respectClientAccentColor diff --git a/Packages/vChewing_Shared/Sources/Shared/Protocols/CtlCandidateProtocol.swift b/Packages/vChewing_Shared/Sources/Shared/Protocols/CtlCandidateProtocol.swift index b74b09bc..3175dc90 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 showCodePointForCurrentCandidate: Bool { get } var shouldAutoExpandCandidates: Bool { get } var isCandidateContextMenuEnabled: Bool { get } var showReverseLookupResult: Bool { get }