From 21ed1187a4f4542a0b51f77f8745d50b610aef0a Mon Sep 17 00:00:00 2001 From: Pete Schaffner Date: Mon, 26 Feb 2024 10:03:14 +0100 Subject: [PATCH] Select and uzoom when clicking button in unselected tab --- .../Features/Terminal/TerminalWindow.swift | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/macos/Sources/Features/Terminal/TerminalWindow.swift b/macos/Sources/Features/Terminal/TerminalWindow.swift index c8061d7fa..c8e194644 100644 --- a/macos/Sources/Features/Terminal/TerminalWindow.swift +++ b/macos/Sources/Features/Terminal/TerminalWindow.swift @@ -17,7 +17,11 @@ class TerminalWindow: NSWindow { private lazy var resetZoomToolbarButton: NSButton = generateResetZoomButton() - private lazy var resetZoomTabButton: NSButton = generateResetZoomButton() + private lazy var resetZoomTabButton: NSButton = { + let button = generateResetZoomButton() + button.action = #selector(selectTabAndZoom(_:)) + return button + }() private lazy var resetZoomTitlebarAccessoryViewController: NSTitlebarAccessoryViewController? = { guard let titlebarContainer = contentView?.superview?.subviews.first(where: { $0.className == "NSTitlebarContainerView" }) else { return nil } @@ -115,7 +119,6 @@ class TerminalWindow: NSWindow { super.becomeKey() updateNewTabButtonOpacity() - resetZoomTabButton.isEnabled = true resetZoomTabButton.contentTintColor = .controlAccentColor resetZoomToolbarButton.contentTintColor = .controlAccentColor } @@ -124,8 +127,7 @@ class TerminalWindow: NSWindow { super.resignKey() updateNewTabButtonOpacity() - resetZoomTabButton.isEnabled = false - resetZoomTabButton.contentTintColor = .labelColor + resetZoomTabButton.contentTintColor = .secondaryLabelColor resetZoomToolbarButton.contentTintColor = .tertiaryLabelColor } @@ -259,6 +261,20 @@ class TerminalWindow: NSWindow { return button } + @objc private func selectTabAndZoom(_ sender: NSButton) { + guard let tabGroup else { return } + + guard let associatedWindow = tabGroup.windows.first(where: { + guard let accessoryView = $0.tab.accessoryView else { return false } + return accessoryView.subviews.contains(sender) + }), + let windowController = associatedWindow.windowController as? TerminalController + else { return } + + tabGroup.selectedWindow = associatedWindow + windowController.splitZoom(self) + } + // MARK: - Titlebar Tabs // Used by the window controller to enable/disable titlebar tabs.