diff --git a/macos/Sources/Features/Terminal/Window Styles/TerminalWindow.swift b/macos/Sources/Features/Terminal/Window Styles/TerminalWindow.swift index 6605bf9ef..ac1d2b881 100644 --- a/macos/Sources/Features/Terminal/Window Styles/TerminalWindow.swift +++ b/macos/Sources/Features/Terminal/Window Styles/TerminalWindow.swift @@ -184,6 +184,10 @@ class TerminalWindow: NSWindow { return } + if tabTitleEditor.handleRightMouseDown(event) { + return + } + super.sendEvent(event) } @@ -840,29 +844,3 @@ extension TerminalWindow: TabTitleEditorDelegate { makeFirstResponder(focusedSurface) } } - -// MARK: - Tab Clicks - -extension TerminalWindow { - /// Handles a middle-click event to close the tab under the cursor - /// - /// Returns true if the event was handled and should be consumed - func handleTabBarMiddleClick(_ event: NSEvent) -> Bool { - // Require middle click - guard event.type == .otherMouseDown && event.buttonNumber == 2 else { return false } - - // Require tab hit - let screenPoint = convertPoint(toScreen: event.locationInWindow) - guard let hit = tabButtonHit(atScreenPoint: screenPoint) else { return false } - - // Require we have tabs and the index is valid - guard let tabbedWindows = tabbedWindows, - hit.index < tabbedWindows.count else { return false } - - // Find the controller and close it - let targetWindow = tabbedWindows[hit.index] - guard let controller = targetWindow.windowController as? TerminalController else { return false } - controller.closeTab(nil) - return true - } -} diff --git a/macos/Sources/Features/Terminal/Window Styles/TitlebarTabsTahoeTerminalWindow.swift b/macos/Sources/Features/Terminal/Window Styles/TitlebarTabsTahoeTerminalWindow.swift index 9e7bbc1c3..2bf3bd42f 100644 --- a/macos/Sources/Features/Terminal/Window Styles/TitlebarTabsTahoeTerminalWindow.swift +++ b/macos/Sources/Features/Terminal/Window Styles/TitlebarTabsTahoeTerminalWindow.swift @@ -67,45 +67,6 @@ 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 viewModel.hasTabBar else { - super.sendEvent(event) - return - } - - // Handle middle-click to close tabs if configured - if handleTabBarMiddleClick(event) { return } - - let isRightClick = - event.type == .rightMouseDown || - (event.type == .otherMouseDown && event.buttonNumber == 2) || - (event.type == .leftMouseDown && event.modifierFlags.contains(.control)) - guard isRightClick else { - super.sendEvent(event) - return - } - - guard let tabBarView else { - super.sendEvent(event) - return - } - - guard !tabTitleEditor.handleRightMouseDown(event) else { - 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 // this, detect the tab bar being added, and override its behavior. override func addTitlebarAccessoryViewController(_ childViewController: NSTitlebarAccessoryViewController) { diff --git a/macos/Sources/Features/Terminal/Window Styles/TitlebarTabsVenturaTerminalWindow.swift b/macos/Sources/Features/Terminal/Window Styles/TitlebarTabsVenturaTerminalWindow.swift index 25a0acc91..fe83fc5fd 100644 --- a/macos/Sources/Features/Terminal/Window Styles/TitlebarTabsVenturaTerminalWindow.swift +++ b/macos/Sources/Features/Terminal/Window Styles/TitlebarTabsVenturaTerminalWindow.swift @@ -69,11 +69,6 @@ class TitlebarTabsVenturaTerminalWindow: TerminalWindow { tab.attributedTitle = attributedTitle } - override func sendEvent(_ event: NSEvent) { - if tabBarView != nil && handleTabBarMiddleClick(event) { return } - super.sendEvent(event) - } - override func layoutIfNeeded() { super.layoutIfNeeded() diff --git a/macos/Sources/Helpers/TabTitleEditor.swift b/macos/Sources/Helpers/TabTitleEditor.swift index 4be2c5306..3e04d73c1 100644 --- a/macos/Sources/Helpers/TabTitleEditor.swift +++ b/macos/Sources/Helpers/TabTitleEditor.swift @@ -125,6 +125,7 @@ final class TabTitleEditor: NSObject, NSTextFieldDelegate { /// /// If this returns true then the event was handled by the coordinator. func handleRightMouseDown(_ event: NSEvent) -> Bool { + guard event.type == .rightMouseDown else { return false } if isMouseEventWithinEditor(event) { inlineTitleEditor?.rightMouseDown(with: event) return true