From c57b91b7785498c0bd52ffd68f4c6fc0dda8503e Mon Sep 17 00:00:00 2001 From: Lawrence Chen Date: Tue, 17 Mar 2026 05:00:25 -0700 Subject: [PATCH 1/3] Add failing empty tab bar double-click test --- Tests/BonsplitTests/BonsplitTests.swift | 82 +++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/Tests/BonsplitTests/BonsplitTests.swift b/Tests/BonsplitTests/BonsplitTests.swift index 6ad08e61..08ec881d 100644 --- a/Tests/BonsplitTests/BonsplitTests.swift +++ b/Tests/BonsplitTests/BonsplitTests.swift @@ -66,6 +66,16 @@ final class BonsplitTests: XCTestCase { } } + private final class NewTabRequestDelegateSpy: BonsplitDelegate { + var requestedKind: String? + var requestedPaneId: PaneID? + + func splitTabBar(_ controller: BonsplitController, didRequestNewTab kind: String, inPane pane: PaneID) { + requestedKind = kind + requestedPaneId = pane + } + } + @MainActor func testControllerCreation() { let controller = BonsplitController() @@ -497,6 +507,52 @@ final class BonsplitTests: XCTestCase { XCTAssertEqual(spy.paneId, pane) } + @MainActor + func testDoubleClickingEmptyTrailingTabBarSpaceRequestsNewTerminalTab() { + let appearance = BonsplitConfiguration.Appearance(showSplitButtons: false) + let configuration = BonsplitConfiguration(appearance: appearance) + let controller = BonsplitController(configuration: configuration) + let pane = controller.internalController.rootNode.allPanes.first! + let spy = NewTabRequestDelegateSpy() + controller.delegate = spy + + let hostingView = NSHostingView( + rootView: TabBarView(pane: pane, isFocused: true, showSplitButtons: false) + .environment(controller) + .environment(controller.internalController) + ) + let window = NSWindow( + contentRect: NSRect(x: 0, y: 0, width: 480, height: 60), + styleMask: [.titled, .closable], + backing: .buffered, + defer: false + ) + defer { window.orderOut(nil) } + guard let contentView = window.contentView else { + XCTFail("Expected content view") + return + } + + hostingView.frame = contentView.bounds + hostingView.autoresizingMask = [.width, .height] + contentView.addSubview(hostingView) + + window.makeKeyAndOrderFront(nil) + contentView.layoutSubtreeIfNeeded() + RunLoop.current.run(until: Date().addingTimeInterval(0.05)) + contentView.layoutSubtreeIfNeeded() + + let clickPoint = NSPoint(x: hostingView.bounds.maxX - 12, y: hostingView.bounds.midY) + guard let event = try? makeLeftMouseDownEvent(in: hostingView, at: clickPoint, clickCount: 2) else { + XCTFail("Expected mouse event") + return + } + NSApp.sendEvent(event) + + XCTAssertEqual(spy.requestedKind, "terminal") + XCTAssertEqual(spy.requestedPaneId, pane.id) + } + func testIconSaturationKeepsRasterFaviconInColorWhenInactive() { XCTAssertEqual( TabItemStyling.iconSaturation(hasRasterIcon: true, tabSaturation: 0.0), @@ -937,4 +993,30 @@ final class BonsplitTests: XCTestCase { y < bitmap.pixelsHigh else { return nil } return bitmap.colorAt(x: x, y: y) } + + @MainActor + private func makeLeftMouseDownEvent( + in view: NSView, + at point: NSPoint, + clickCount: Int + ) throws -> NSEvent { + guard let window = view.window else { + throw NSError(domain: "BonsplitTests", code: 1, userInfo: [NSLocalizedDescriptionKey: "Missing window"]) + } + let pointInWindow = view.convert(point, to: nil) + guard let event = NSEvent.mouseEvent( + with: .leftMouseDown, + location: pointInWindow, + modifierFlags: [], + timestamp: ProcessInfo.processInfo.systemUptime, + windowNumber: window.windowNumber, + context: nil, + eventNumber: 0, + clickCount: clickCount, + pressure: 1 + ) else { + throw NSError(domain: "BonsplitTests", code: 2, userInfo: [NSLocalizedDescriptionKey: "Failed to create mouse event"]) + } + return event + } } From 582285396509b1cbdeb515f34bd49944732bd643 Mon Sep 17 00:00:00 2001 From: Lawrence Chen Date: Tue, 17 Mar 2026 05:00:40 -0700 Subject: [PATCH 2/3] Handle empty tab bar double clicks --- .../Bonsplit/Internal/Views/TabBarView.swift | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/Sources/Bonsplit/Internal/Views/TabBarView.swift b/Sources/Bonsplit/Internal/Views/TabBarView.swift index 4f2a5d38..98f689fa 100644 --- a/Sources/Bonsplit/Internal/Views/TabBarView.swift +++ b/Sources/Bonsplit/Internal/Views/TabBarView.swift @@ -139,6 +139,11 @@ struct TabBarView: View { Color.clear .frame(width: trailing, height: TabBarMetrics.tabHeight) .contentShape(Rectangle()) + .background( + EmptyTabBarDoubleClickMonitorView { + controller.requestNewTab(kind: "terminal", inPane: pane.id) + } + ) .onDrop(of: [.tabTransfer], delegate: TabDropDelegate( targetIndex: pane.tabs.count, pane: pane, @@ -413,6 +418,11 @@ struct TabBarView: View { .fill(Color.clear) .frame(width: 30, height: TabBarMetrics.tabHeight) .contentShape(Rectangle()) + .background( + EmptyTabBarDoubleClickMonitorView { + controller.requestNewTab(kind: "terminal", inPane: pane.id) + } + ) .onDrop(of: [.tabTransfer], delegate: TabDropDelegate( targetIndex: pane.tabs.count, pane: pane, @@ -568,6 +578,53 @@ private struct SplitActionButtonStyle: ButtonStyle { } } +private struct EmptyTabBarDoubleClickMonitorView: NSViewRepresentable { + let onDoubleClick: () -> Void + + final class Coordinator { + var onDoubleClick: (() -> Void)? + weak var view: NSView? + var monitor: Any? + + deinit { + if let monitor { + NSEvent.removeMonitor(monitor) + } + } + } + + func makeCoordinator() -> Coordinator { Coordinator() } + + func makeNSView(context: Context) -> NSView { + let view = NSView(frame: .zero) + view.wantsLayer = true + view.layer?.backgroundColor = NSColor.clear.cgColor + + context.coordinator.view = view + context.coordinator.onDoubleClick = onDoubleClick + + let coordinator = context.coordinator + coordinator.monitor = NSEvent.addLocalMonitorForEvents(matching: [.leftMouseDown]) { [weak coordinator] event in + guard event.clickCount >= 2 else { return event } + guard let coordinator, let view = coordinator.view, let window = view.window else { return event } + guard event.window === window else { return event } + + let point = view.convert(event.locationInWindow, from: nil) + guard view.bounds.contains(point) else { return event } + + coordinator.onDoubleClick?() + return nil + } + + return view + } + + func updateNSView(_ nsView: NSView, context: Context) { + context.coordinator.view = nsView + context.coordinator.onDoubleClick = onDoubleClick + } +} + enum TabControlShortcutModifier: Equatable { case control case command From f6d6ab720f3f796dc10c11b258071d2ae0aae624 Mon Sep 17 00:00:00 2001 From: Lawrence Chen Date: Tue, 17 Mar 2026 15:01:18 -0700 Subject: [PATCH 3/3] Only consume handled tab bar double clicks --- Sources/Bonsplit/Internal/Views/TabBarView.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Sources/Bonsplit/Internal/Views/TabBarView.swift b/Sources/Bonsplit/Internal/Views/TabBarView.swift index 98f689fa..8c33b393 100644 --- a/Sources/Bonsplit/Internal/Views/TabBarView.swift +++ b/Sources/Bonsplit/Internal/Views/TabBarView.swift @@ -141,7 +141,9 @@ struct TabBarView: View { .contentShape(Rectangle()) .background( EmptyTabBarDoubleClickMonitorView { + guard splitViewController.isInteractive else { return false } controller.requestNewTab(kind: "terminal", inPane: pane.id) + return true } ) .onDrop(of: [.tabTransfer], delegate: TabDropDelegate( @@ -420,7 +422,9 @@ struct TabBarView: View { .contentShape(Rectangle()) .background( EmptyTabBarDoubleClickMonitorView { + guard splitViewController.isInteractive else { return false } controller.requestNewTab(kind: "terminal", inPane: pane.id) + return true } ) .onDrop(of: [.tabTransfer], delegate: TabDropDelegate( @@ -579,10 +583,10 @@ private struct SplitActionButtonStyle: ButtonStyle { } private struct EmptyTabBarDoubleClickMonitorView: NSViewRepresentable { - let onDoubleClick: () -> Void + let onDoubleClick: () -> Bool final class Coordinator { - var onDoubleClick: (() -> Void)? + var onDoubleClick: (() -> Bool)? weak var view: NSView? var monitor: Any? @@ -612,7 +616,7 @@ private struct EmptyTabBarDoubleClickMonitorView: NSViewRepresentable { let point = view.convert(event.locationInWindow, from: nil) guard view.bounds.contains(point) else { return event } - coordinator.onDoubleClick?() + guard coordinator.onDoubleClick?() == true else { return event } return nil }