Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
32 changes: 31 additions & 1 deletion Sources/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2055,6 +2055,29 @@ struct ContentView: View {
return -max(0, min(titlebarPadding, hostingSafeAreaTop))
}

static func customTitlebarLeadingPadding(
isFullScreen: Bool,
isSidebarVisible: Bool,
sidebarWidth: CGFloat,
minimumSidebarWidth: CGFloat,
titlebarLeadingInset: CGFloat
) -> CGFloat {
if isFullScreen && !isSidebarVisible {
return 8
}

let minimumSidebarTitleInset = max(titlebarLeadingInset, minimumSidebarWidth + 12)
guard isSidebarVisible else {
return minimumSidebarTitleInset
}

let visibleSidebarTitleInset = sidebarWidth + 12
guard sidebarWidth > minimumSidebarWidth + 0.5 else {
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 The 0.5 sub-pixel tolerance that separates "at minimum width" from "wider than minimum" is not explained. Without a comment, future readers may wonder whether this is pixels, points, a render artifact, or an arbitrary guard. A brief inline note stating that it absorbs floating-point drift around the minimum clamp would make the intent clear.

Suggested change
guard sidebarWidth > minimumSidebarWidth + 0.5 else {
// Use a 0.5-point tolerance to absorb floating-point drift at the minimum-width clamp.
guard sidebarWidth > minimumSidebarWidth + 0.5 else {

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added an inline note explaining the 0.5-point tolerance around the minimum-width clamp.

— Claude Code

return minimumSidebarTitleInset
}
return max(minimumSidebarTitleInset, visibleSidebarTitleInset)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
}

private func terminalContent(appearance: WindowAppearanceSnapshot) -> some View {
let mountedWorkspaceIdSet = Set(mountedWorkspaceIds)
let mountedWorkspaces = tabManager.tabs.filter { mountedWorkspaceIdSet.contains($0.id) }
Expand Down Expand Up @@ -2334,6 +2357,13 @@ struct ContentView: View {

private func customTitlebar(appearance: WindowAppearanceSnapshot) -> some View {
let titlebarContentHeight = max(1, WindowChromeMetrics.appTitlebarHeight - 2)
let leadingPadding = Self.customTitlebarLeadingPadding(
isFullScreen: isFullScreen,
isSidebarVisible: sidebarState.isVisible,
sidebarWidth: sidebarWidth,
minimumSidebarWidth: minimumSidebarWidth,
titlebarLeadingInset: titlebarLeadingInset
)
return ZStack {
// Enable window dragging from the titlebar strip without making the entire content
// view draggable (which breaks drag gestures like tab reordering).
Expand Down Expand Up @@ -2365,7 +2395,7 @@ struct ContentView: View {
}
.frame(height: titlebarContentHeight)
.padding(.top, 2)
.padding(.leading, (isFullScreen && !sidebarState.isVisible) ? 8 : (sidebarState.isVisible ? sidebarWidth + 12 : titlebarLeadingInset))
.padding(.leading, leadingPadding)
.padding(.trailing, 8)
}
.frame(height: WindowChromeMetrics.appTitlebarHeight)
Expand Down
68 changes: 68 additions & 0 deletions cmuxTests/WindowAndDragTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1958,6 +1958,74 @@ final class TitlebarLeadingInsetPassthroughViewTests: XCTestCase {
}


final class CustomTitlebarLeadingPaddingTests: XCTestCase {
func testHiddenSidebarUsesMinimumSidebarTitleInset() {
XCTAssertEqual(
ContentView.customTitlebarLeadingPadding(
isFullScreen: false,
isSidebarVisible: false,
sidebarWidth: 216,
minimumSidebarWidth: 216,
titlebarLeadingInset: 82
),
228
)
}

func testMinimumWidthVisibleSidebarMatchesHiddenSidebarTitleInset() {
let hidden = ContentView.customTitlebarLeadingPadding(
isFullScreen: false,
isSidebarVisible: false,
sidebarWidth: 216,
minimumSidebarWidth: 216,
titlebarLeadingInset: 82
)
let visible = ContentView.customTitlebarLeadingPadding(
isFullScreen: false,
isSidebarVisible: true,
sidebarWidth: 216,
minimumSidebarWidth: 216,
titlebarLeadingInset: 82
)

XCTAssertEqual(visible, hidden)
}

func testWiderSidebarPushesTitlebarContentRight() {
let hidden = ContentView.customTitlebarLeadingPadding(
isFullScreen: false,
isSidebarVisible: false,
sidebarWidth: 216,
minimumSidebarWidth: 216,
titlebarLeadingInset: 82
)
let visible = ContentView.customTitlebarLeadingPadding(
isFullScreen: false,
isSidebarVisible: true,
sidebarWidth: 320,
minimumSidebarWidth: 216,
titlebarLeadingInset: 82
)

XCTAssertGreaterThan(visible, hidden)
XCTAssertEqual(visible, 332)
}

func testFullscreenHiddenSidebarKeepsCompactInset() {
XCTAssertEqual(
ContentView.customTitlebarLeadingPadding(
isFullScreen: true,
isSidebarVisible: false,
sidebarWidth: 216,
minimumSidebarWidth: 216,
titlebarLeadingInset: 82
),
8
)
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated


@MainActor
final class FolderWindowMoveSuppressionTests: XCTestCase {
private func makeWindow() -> NSWindow {
Expand Down
Loading