From ff2df510d76fb495c71ad5fdc555081d5f80ca58 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Tue, 5 Sep 2023 15:38:47 +0800 Subject: [PATCH] TooltipUI // Auto-close out-of-date window instances. --- .../vChewing_TooltipUI/Sources/TooltipUI/TooltipUI.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Packages/vChewing_TooltipUI/Sources/TooltipUI/TooltipUI.swift b/Packages/vChewing_TooltipUI/Sources/TooltipUI/TooltipUI.swift index 4d3fac87..374d0325 100644 --- a/Packages/vChewing_TooltipUI/Sources/TooltipUI/TooltipUI.swift +++ b/Packages/vChewing_TooltipUI/Sources/TooltipUI/TooltipUI.swift @@ -20,6 +20,12 @@ public class TooltipUI: NSWindowController { } } + private static var currentWindow: NSWindow? { + willSet { + currentWindow?.orderOut(nil) + } + } + public var direction: NSAttributedTooltipTextView.writingDirection = .horizontal { didSet { if #unavailable(macOS 10.13) { direction = .horizontal } @@ -47,6 +53,7 @@ public class TooltipUI: NSWindowController { messageText.textColor = NSColor.textColor messageText.needsDisplay = true panel.contentView?.addSubview(messageText) + Self.currentWindow = panel super.init(window: panel) }