macos: remove the tabBarView variable we can search it

pull/9831/head
Mitchell Hashimoto 2025-12-10 20:09:26 -08:00
parent 969bcbe8e3
commit 76c2de6088
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
1 changed files with 16 additions and 15 deletions

View File

@ -8,9 +8,6 @@ import SwiftUI
class TitlebarTabsTahoeTerminalWindow: TransparentTitlebarTerminalWindow, NSToolbarDelegate {
/// The view model for SwiftUI views
private var viewModel = ViewModel()
/// Tab bar view for event routing
private weak var tabBarView: NSView?
/// Titlebar tabs can't support the update accessory because of the way we layout
/// the native tabs back into the menu bar.
@ -71,27 +68,35 @@ class TitlebarTabsTahoeTerminalWindow: TransparentTitlebarTerminalWindow, NSTool
viewModel.isMainWindow = false
}
/// On our Tahoe titlebar tabs, we need to fix up right click events because they don't work
/// naturally due to whatever mess we made.
override func sendEvent(_ event: NSEvent) {
guard let tabBarView, viewModel.hasTabBar else {
guard viewModel.hasTabBar else {
super.sendEvent(event)
return
}
let isRightClick =
event.type == .rightMouseDown ||
(event.type == .otherMouseDown && event.buttonNumber == 2)
(event.type == .otherMouseDown && event.buttonNumber == 2) ||
(event.type == .leftMouseDown && event.modifierFlags.contains(.control))
guard isRightClick else {
super.sendEvent(event)
return
}
let locationInTabBar = tabBarView.convert(event.locationInWindow, from: nil)
if tabBarView.bounds.contains(locationInTabBar) {
tabBarView.rightMouseDown(with: event)
} else {
guard let tabBarView = findTabBar() else {
super.sendEvent(event)
return
}
let locationInTabBar = tabBarView.convert(event.locationInWindow, from: nil)
guard tabBarView.bounds.contains(locationInTabBar) else {
super.sendEvent(event)
return
}
tabBarView.rightMouseDown(with: event)
}
// This is called by macOS for native tabbing in order to add the tab bar. We hook into
@ -175,8 +180,6 @@ class TitlebarTabsTahoeTerminalWindow: TransparentTitlebarTerminalWindow, NSTool
let tabBar = findTabBar()
else { return }
self.tabBarView = tabBar
// View model updates must happen on their own ticks.
DispatchQueue.main.async { [weak self] in
self?.viewModel.hasTabBar = true
@ -235,7 +238,6 @@ class TitlebarTabsTahoeTerminalWindow: TransparentTitlebarTerminalWindow, NSTool
// Remove the observer so we can call setup again.
self.tabBarObserver = nil
self.tabBarView = nil
// Wait a tick to let the new tab bars appear and then set them up.
DispatchQueue.main.async {
@ -253,7 +255,6 @@ class TitlebarTabsTahoeTerminalWindow: TransparentTitlebarTerminalWindow, NSTool
// Clear our observations
self.tabBarObserver = nil
self.tabBarView = nil
}
// MARK: NSToolbarDelegate