Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Sources/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2994,11 +2994,7 @@ struct ContentView: View {

private func syncTrafficLightInset() {
let inset: CGFloat = (isMinimalMode && !sidebarState.isVisible && !isFullScreen) ? 80 : 0
for tab in tabManager.tabs {
if tab.bonsplitController.configuration.appearance.tabBarLeadingInset != inset {
tab.bonsplitController.configuration.appearance.tabBarLeadingInset = inset
}
}
tabManager.syncWorkspaceTabBarLeadingInset(inset)
}

private func updateTitlebarText() {
Expand Down Expand Up @@ -3732,6 +3728,10 @@ struct ContentView: View {
syncTrafficLightInset()
})

view = AnyView(view.onChange(of: tabManager.tabs.map(\.id)) { _ in
syncTrafficLightInset()
})
Comment on lines +3747 to +3749

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Inconsistent onChange closure arity

The new handler uses the single-argument (old/deprecated) onChange form while the immediately-preceding handler on line 3727 uses the two-argument (oldValue, newValue) form that is consistent with the rest of this function. Both work at runtime, but mixing the two APIs may generate a deprecation warning in newer Xcode versions and is inconsistent with the surrounding code.

Suggested change
view = AnyView(view.onChange(of: tabManager.tabs.map(\.id)) { _ in
syncTrafficLightInset()
})
view = AnyView(view.onChange(of: tabManager.tabs.map(\.id)) { _, _ in
syncTrafficLightInset()
})


view = AnyView(view.onChange(of: sidebarState.persistedWidth) { newValue in
let sanitized = normalizedSidebarWidth(newValue)
if abs(newValue - sanitized) > 0.5 {
Expand Down
22 changes: 18 additions & 4 deletions Sources/TabManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,7 @@ class TabManager: ObservableObject {
private var workspaceCycleCooldownTask: Task<Void, Never>?
private var pendingWorkspaceUnfocusTarget: (tabId: UUID, panelId: UUID)?
private var sidebarSelectedWorkspaceIds: Set<UUID> = []
private var currentWindowTabBarLeadingInset: CGFloat?
private var closeConfirmationInFlight = false
var confirmCloseHandler: ((String, String, Bool) -> Bool)?
private struct WorkspaceCreationTabSnapshot {
Expand Down Expand Up @@ -1943,13 +1944,26 @@ class TabManager: ObservableObject {
to newWorkspace: Workspace,
from sourceWorkspace: Workspace?
) {
guard let sourceWorkspace else { return }
// Sidebar-toggle relayout updates the live Bonsplit leading inset so minimal-mode
// workspaces reserve traffic-light space. New workspaces need that same inset
// copied immediately because creation itself does not trigger the resync path.
let inheritedLeadingInset = sourceWorkspace.bonsplitController.configuration.appearance.tabBarLeadingInset
if newWorkspace.bonsplitController.configuration.appearance.tabBarLeadingInset != inheritedLeadingInset {
newWorkspace.bonsplitController.configuration.appearance.tabBarLeadingInset = inheritedLeadingInset
let inheritedLeadingInset = currentWindowTabBarLeadingInset
?? sourceWorkspace?.bonsplitController.configuration.appearance.tabBarLeadingInset
guard let inheritedLeadingInset else { return }
Comment on lines +1950 to +1952

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 First-workspace creation with uninitialised cache

If currentWindowTabBarLeadingInset is still nil (i.e. syncWorkspaceTabBarLeadingInset has not yet been called by ContentView) and sourceWorkspace is also nil, inheritedLeadingInset resolves to nil and the guard exits — leaving the new workspace with whatever default inset its BonsplitController happened to have. In practice the run-loop round-trip before workspace creation means the value is already populated, but there's no longer a hard guarantee from the type system. The old code had the same hole (guard let sourceWorkspace else { return }), so this is not a regression; just worth a comment clarifying the invariant.

applyTabBarLeadingInset(inheritedLeadingInset, to: newWorkspace)
}

func syncWorkspaceTabBarLeadingInset(_ inset: CGFloat) {
let normalizedInset = max(0, inset)
currentWindowTabBarLeadingInset = normalizedInset
for tab in tabs {
applyTabBarLeadingInset(normalizedInset, to: tab)
}
}

private func applyTabBarLeadingInset(_ inset: CGFloat, to workspace: Workspace) {
if workspace.bonsplitController.configuration.appearance.tabBarLeadingInset != inset {
workspace.bonsplitController.configuration.appearance.tabBarLeadingInset = inset
}
}

Expand Down
60 changes: 60 additions & 0 deletions cmuxTests/AppDelegateShortcutRoutingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1598,6 +1598,66 @@ final class AppDelegateShortcutRoutingTests: XCTestCase {
)
}

func testMinimalModeCollapsedSidebarResyncsTrafficLightInsetAfterNewWorkspaceCreation() {
guard let appDelegate = AppDelegate.shared else {
XCTFail("Expected AppDelegate.shared")
return
}

let defaults = UserDefaults.standard
let savedMode = defaults.object(forKey: WorkspacePresentationModeSettings.modeKey)
defaults.set(WorkspacePresentationModeSettings.Mode.minimal.rawValue, forKey: WorkspacePresentationModeSettings.modeKey)
defer {
restoreDefaultsValue(savedMode, forKey: WorkspacePresentationModeSettings.modeKey, defaults: defaults)
}

let snapshot = SessionWindowSnapshot(
frame: nil,
display: nil,
tabManager: SessionTabManagerSnapshot(selectedWorkspaceIndex: nil, workspaces: []),
sidebar: SessionSidebarSnapshot(isVisible: false, selection: .tabs, width: nil)
)
let windowId = appDelegate.createMainWindow(sessionWindowSnapshot: snapshot)
defer { closeWindow(withId: windowId) }

guard let manager = appDelegate.tabManagerFor(windowId: windowId) else {
XCTFail("Expected tab manager for created window")
return
}

RunLoop.main.run(until: Date(timeIntervalSinceNow: 0.1))

XCTAssertEqual(appDelegate.sidebarVisibility(windowId: windowId), false)

guard let sourceWorkspace = manager.selectedWorkspace else {
XCTFail("Expected selected workspace")
return
}

// Recreate the regression shape: the window chrome state says minimal +
// collapsed sidebar, but the selected workspace's live Bonsplit inset is stale.
sourceWorkspace.bonsplitController.configuration.appearance.tabBarLeadingInset = 0

guard let newWorkspaceId = appDelegate.addWorkspaceInPreferredMainWindow(debugSource: "test.issue2737") else {
XCTFail("Expected workspace creation to route to the test window")
return
}

RunLoop.main.run(until: Date(timeIntervalSinceNow: 0.1))

guard let newWorkspace = manager.tabs.first(where: { $0.id == newWorkspaceId }) else {
XCTFail("Expected new workspace in test window")
return
}

XCTAssertEqual(
newWorkspace.bonsplitController.configuration.appearance.tabBarLeadingInset,
80,
accuracy: 0.5,
"New minimal-mode workspaces should reserve traffic-light space immediately even when the source workspace inset is stale"
)
}

func testAttachUpdateAccessoryRemovesTitlebarAccessoryWhenMinimalModeEnabled() {
guard let appDelegate = AppDelegate.shared else {
XCTFail("Expected AppDelegate.shared")
Expand Down
Loading