diff --git a/.github/swift-file-length-budget.tsv b/.github/swift-file-length-budget.tsv index 7e21b9355f1e..603bd30a0913 100644 --- a/.github/swift-file-length-budget.tsv +++ b/.github/swift-file-length-budget.tsv @@ -4,12 +4,12 @@ 32553 CLI/cmux.swift 21996 Sources/TerminalController.swift 19875 Sources/Workspace.swift -19052 Sources/ContentView.swift +19152 Sources/ContentView.swift 17920 Sources/AppDelegate.swift 16522 Sources/GhosttyTerminalView.swift 13589 Sources/Panels/BrowserPanel.swift 11916 cmuxTests/AppDelegateShortcutRoutingTests.swift -9914 Sources/TabManager.swift +9939 Sources/TabManager.swift 8494 cmuxTests/CLINotifyProcessIntegrationRegressionTests.swift 7737 Sources/Panels/BrowserPanelView.swift 7214 cmuxTests/WorkspaceUnitTests.swift @@ -97,7 +97,7 @@ 866 Sources/CommandPalette/CommandPaletteSettingsToggle.swift 863 Sources/Panels/TerminalPanel.swift 856 Packages/CmuxSettingsUI/Sources/CmuxSettingsUI/Sections/AppSection.swift -853 cmuxTests/WorkspaceGroupTests.swift +913 cmuxTests/WorkspaceGroupTests.swift 846 cmuxTests/AgentSessionAutoResumeSettingsTests.swift 845 cmuxTests/SSHStartupSignalLifecycleTests.swift 842 Sources/Panels/MarkdownWebRenderer.swift @@ -156,6 +156,7 @@ 668 cmuxTests/FeedCoordinatorTests.swift 574 Sources/Feed/FeedTextEditorDebugWindowController.swift 568 Packages/CMUXMobileCore/Sources/CMUXMobileCore/MobileTerminalRenderGrid.swift +566 Packages/CMUXAgentLaunch/Sources/CMUXAgentLaunch/AgentLaunchSanitizer.swift 562 cmuxTests/AgentExecutableResolverTests.swift 560 cmuxTests/GhosttyConfigPathResolverTests.swift 558 Packages/CmuxGit/Sources/CmuxGit/Parsing/GitMetadataService+Config.swift diff --git a/Sources/ContentView.swift b/Sources/ContentView.swift index 66aafe72923e..a64d6ea69163 100644 --- a/Sources/ContentView.swift +++ b/Sources/ContentView.swift @@ -10585,6 +10585,7 @@ struct VerticalTabsSidebar: View { // row sitting behind the open menu. See `SidebarShortcutHintFreezePolicy`. @State private var frozenShortcutHintsTabId: UUID? @State private var frozenShortcutHintsValue: Bool = false + @State private var workspaceRowsMeasurement: SidebarWorkspaceRowsMeasurement? @State private var pendingSelectedWorkspaceScrollId: UUID? @State private var collapsedExtensionSidebarSectionIds: Set = [] @State private var extensionSidebarWorktreeCreationInFlightSectionIds: Set = [] @@ -10945,6 +10946,8 @@ struct VerticalTabsSidebar: View { let workspaceGroups: [WorkspaceGroup] let workspaceGroupById: [UUID: WorkspaceGroup] let workspaceGroupMenuSnapshot: WorkspaceGroupMenuSnapshot + let workspaceRenderItems: [SidebarWorkspaceRenderItem] + let visibleWorkspaceRowIds: [UUID] var workspaceIds: [UUID] { tabIds } } @@ -10975,6 +10978,11 @@ struct VerticalTabsSidebar: View { let workspaceGroupMenuSnapshot = WorkspaceGroupMenuSnapshot( items: workspaceGroups.map { WorkspaceGroupMenuSnapshot.Item(id: $0.id, name: $0.name) } ) + let workspaceRenderItems = SidebarWorkspaceRenderItem.renderItems( + tabs: tabs, + groupsById: workspaceGroupById + ) + let visibleWorkspaceRowIds = workspaceRenderItems.map(\.rowWorkspaceId) let draggedSidebarTabId = dragState.draggedTabId let sidebarReorderIds = draggedSidebarTabId.map { tabManager.sidebarReorderWorkspaceIds( @@ -10999,7 +11007,9 @@ struct VerticalTabsSidebar: View { allSelectedRemoteContextMenuTargetsDisconnected: allSelectedRemoteContextMenuTargetsDisconnected, workspaceGroups: workspaceGroups, workspaceGroupById: workspaceGroupById, - workspaceGroupMenuSnapshot: workspaceGroupMenuSnapshot + workspaceGroupMenuSnapshot: workspaceGroupMenuSnapshot, + workspaceRenderItems: workspaceRenderItems, + visibleWorkspaceRowIds: visibleWorkspaceRowIds ) ZStack(alignment: .bottomLeading) { @@ -11100,18 +11110,36 @@ struct VerticalTabsSidebar: View { private func workspaceScrollArea(renderContext: WorkspaceListRenderContext) -> some View { let scrollInsets = SidebarWorkspaceScrollInsets.workspaceList return GeometryReader { geometryProxy in + let contentMinHeight = SidebarWorkspaceScrollLayout.contentMinHeight( + viewportHeight: geometryProxy.size.height, + insets: scrollInsets + ) + let measuredWorkspaceRowsHeight = workspaceRowsMeasurement?.rowsHeight( + for: renderContext.visibleWorkspaceRowIds + ) + // The empty drop/tap area below the last row is sized to the + // remaining viewport so the scroll content fills (but never + // exceeds) the visible height when the rows fit. Sizing it to a + // finite remainder — instead of the old `maxHeight: .infinity` — + // is what keeps the document view from always overflowing, so the + // overlay scroller stays hidden when there is nothing to scroll + // (https://github.com/manaflow-ai/cmux/issues/3241). + let emptyAreaHeight = SidebarWorkspaceScrollLayout.emptyAreaHeight( + contentMinHeight: contentMinHeight, + rowsHeight: measuredWorkspaceRowsHeight + ) + ScrollViewReader { scrollProxy in - ScrollView { + ScrollView(.vertical) { workspaceScrollContent( renderContext: renderContext, - minHeight: SidebarWorkspaceScrollLayout.contentMinHeight( - viewportHeight: geometryProxy.size.height, - insets: scrollInsets - ) + minHeight: contentMinHeight, + emptyAreaHeight: emptyAreaHeight ) } .background( SidebarScrollViewResolver { scrollView in + configureSidebarScrollView(scrollView) dragAutoScrollController.attach(scrollView: scrollView) } .frame(width: 0, height: 0) @@ -11205,6 +11233,12 @@ struct VerticalTabsSidebar: View { } requestSelectedWorkspaceScroll(scrollProxy, renderContext: renderContext) } + .onChange(of: renderContext.visibleWorkspaceRowIds) { _, _ in + // Drop the stale rows-height measurement so the empty-area + // sizing recomputes for the new row set. The measurement is + // also keyed by workspace ids, so this is belt-and-suspenders. + workspaceRowsMeasurement = nil + } .onReceive(NotificationCenter.default.publisher(for: .workspaceOrderDidChange)) { notification in requestSelectedWorkspaceScrollAfterWorkspaceOrderChange(notification) } @@ -11253,10 +11287,35 @@ struct VerticalTabsSidebar: View { lastSidebarSelectionIndex = index } } + .onPreferenceChange(SidebarWorkspaceRowsHeightPreferenceKey.self) { measurement in + guard let measurement else { + workspaceRowsMeasurement = nil + return + } + let nextMeasurement = SidebarWorkspaceRowsMeasurement( + workspaceIds: measurement.workspaceIds, + rowsHeight: max(0, measurement.rowsHeight) + ) + if let workspaceRowsMeasurement, + workspaceRowsMeasurement.isEquivalent(to: nextMeasurement) { + return + } + workspaceRowsMeasurement = nextMeasurement + } } } } + // Applies one stable overlay/autohide scroller config and never toggles it. + // Toggling `hasVerticalScroller`/style from SwiftUI re-renders (constant + // while agents update rows) re-flashes the overlay knob so it never reaches + // its idle fade; a stable config lets AppKit own appear/scroll/fade and the + // finite empty-area height keeps it hidden when content fits (#3241). + private func configureSidebarScrollView(_ scrollView: NSScrollView?) { + guard let scrollView else { return } + SidebarScrollViewConfigurator.apply(to: scrollView) + } + @ViewBuilder private func extensionSidebarScrollArea(renderContext: WorkspaceListRenderContext) -> some View { if effectiveExtensionSidebarProviderId == CmuxExtensionSidebarSelection.hostedExtensionsProviderId { @@ -11376,6 +11435,7 @@ struct VerticalTabsSidebar: View { } .background( SidebarScrollViewResolver { scrollView in + configureSidebarScrollView(scrollView) dragAutoScrollController.attach(scrollView: scrollView) } .frame(width: 0, height: 0) @@ -12349,7 +12409,8 @@ struct VerticalTabsSidebar: View { private func workspaceScrollContent( renderContext: WorkspaceListRenderContext, - minHeight: CGFloat + minHeight: CGFloat, + emptyAreaHeight: CGFloat ) -> some View { VStack(spacing: 0) { workspaceRows(renderContext: renderContext) @@ -12362,19 +12423,17 @@ struct VerticalTabsSidebar: View { dragAutoScrollController: dragAutoScrollController, topDropIndicatorVisible: emptyAreaTopDropIndicatorVisible(), tabDropDelegate: emptyAreaTabDropDelegate(renderContext: renderContext), - bonsplitDropIndicator: dropIndicatorBinding + bonsplitDropIndicator: dropIndicatorBinding, + expandsVertically: false, + minimumHeight: emptyAreaHeight ) - .frame(maxWidth: .infinity, maxHeight: .infinity) } .frame(minHeight: minHeight, alignment: .top) } @ViewBuilder private func workspaceRows(renderContext: WorkspaceListRenderContext) -> some View { - let renderItems = SidebarWorkspaceRenderItem.renderItems( - tabs: renderContext.tabs, - groupsById: renderContext.workspaceGroupById - ) + let renderItems = renderContext.workspaceRenderItems let shouldCollectWorkspaceDropTargets = SidebarDropPlanner.shouldCollectWorkspaceDropTargets( draggedTabId: dragState.draggedTabId, isBonsplitWorkspaceDropActive: isBonsplitWorkspaceDropTargetCollectionActive @@ -12404,6 +12463,18 @@ struct VerticalTabsSidebar: View { } .padding(.vertical, SidebarWorkspaceListMetrics.rowVerticalPadding) .frame(maxWidth: .infinity, alignment: .leading) + let measuredRows = rows + .background { + GeometryReader { proxy in + Color.clear.preference( + key: SidebarWorkspaceRowsHeightPreferenceKey.self, + value: SidebarWorkspaceRowsMeasurement( + workspaceIds: renderContext.visibleWorkspaceRowIds, + rowsHeight: proxy.size.height + ) + ) + } + } // Gate ONLY the per-row frame-anchor *reader* (the virtualization-defeating // work) behind the drag-active check, and keep the Bonsplit drop-capture @@ -12413,7 +12484,7 @@ struct VerticalTabsSidebar: View { // the drop NSView, orphaning the in-flight drag. Applying it at the stable outer // level keeps the NSView identity-stable across gate flips. (#5325 review) rowsWithGatedDropTargetReader( - rows: rows, + rows: measuredRows, renderContext: renderContext, shouldCollect: shouldCollectWorkspaceDropTargets ) @@ -14890,11 +14961,11 @@ private struct SidebarEmptyArea: View { let topDropIndicatorVisible: Bool let tabDropDelegate: SidebarTabDropDelegate let bonsplitDropIndicator: Binding + var expandsVertically = true + var minimumHeight: CGFloat? = nil var body: some View { - Color.clear - .contentShape(Rectangle()) - .frame(maxWidth: .infinity, maxHeight: .infinity) + hitTarget .onTapGesture(count: 2) { tabManager.addWorkspace(placementOverride: .end) if let selectedId = tabManager.selectedTabId { @@ -14923,6 +14994,19 @@ private struct SidebarEmptyArea: View { } } } + + @ViewBuilder + private var hitTarget: some View { + if expandsVertically { + Color.clear + .frame(maxWidth: .infinity, maxHeight: .infinity) + .contentShape(Rectangle()) + } else { + Color.clear + .frame(maxWidth: .infinity, minHeight: minimumHeight ?? 0) + .contentShape(Rectangle()) + } + } } private struct ExtensionSidebarBrowserStackEmptyArea: View { diff --git a/Sources/SidebarScrollViewConfigurator.swift b/Sources/SidebarScrollViewConfigurator.swift new file mode 100644 index 000000000000..8ec4334e1874 --- /dev/null +++ b/Sources/SidebarScrollViewConfigurator.swift @@ -0,0 +1,26 @@ +import AppKit + +/// Applies the sidebar workspace list's stable overlay-scroller configuration. +/// +/// `SidebarScrollViewResolver` re-resolves on every SwiftUI update of the +/// sidebar, so `apply(to:)` is called repeatedly for the same scroll view — +/// including while AppKit is mid-way through an overlay-scroller fade. Any +/// write to these properties (even with an unchanged value) re-tiles the +/// scrollers and can cancel the in-flight fade without rescheduling it, +/// stranding the knob permanently visible (#3241 follow-up). +enum SidebarScrollViewConfigurator { + static func apply(to scrollView: NSScrollView) { + if scrollView.hasHorizontalScroller { + scrollView.hasHorizontalScroller = false + } + if scrollView.scrollerStyle != .overlay { + scrollView.scrollerStyle = .overlay + } + if !scrollView.autohidesScrollers { + scrollView.autohidesScrollers = true + } + if !scrollView.hasVerticalScroller { + scrollView.hasVerticalScroller = true + } + } +} diff --git a/Sources/SidebarWorkspaceRenderItem.swift b/Sources/SidebarWorkspaceRenderItem.swift index ceabeaf594f9..36080cea6d5c 100644 --- a/Sources/SidebarWorkspaceRenderItem.swift +++ b/Sources/SidebarWorkspaceRenderItem.swift @@ -14,6 +14,16 @@ enum SidebarWorkspaceRenderItem { return "workspace.\(workspace.id.uuidString)" } } + + var rowWorkspaceId: UUID { + switch self { + case .groupHeader(let group, _): + return group.anchorWorkspaceId + case .workspace(let workspace): + return workspace.id + } + } + static func renderItems( tabs: [Workspace], groupsById: [UUID: WorkspaceGroup] diff --git a/Sources/SidebarWorkspaceRowsHeightPreferenceKey.swift b/Sources/SidebarWorkspaceRowsHeightPreferenceKey.swift new file mode 100644 index 000000000000..8abd21f95535 --- /dev/null +++ b/Sources/SidebarWorkspaceRowsHeightPreferenceKey.swift @@ -0,0 +1,21 @@ +import Foundation +import SwiftUI + +/// Carries the single whole-content `SidebarWorkspaceRowsMeasurement` of the +/// sidebar workspace rows up to the scroll container, which uses it to size +/// the empty drop/tap area to the remaining viewport (#3241). +struct SidebarWorkspaceRowsHeightPreferenceKey: PreferenceKey { + static let defaultValue: SidebarWorkspaceRowsMeasurement? = nil + + static func reduce( + value: inout SidebarWorkspaceRowsMeasurement?, + nextValue: () -> SidebarWorkspaceRowsMeasurement? + ) { + guard let next = nextValue() else { return } + guard let current = value else { + value = next + return + } + value = current.rowsHeight >= next.rowsHeight ? current : next + } +} diff --git a/Sources/SidebarWorkspaceRowsMeasurement.swift b/Sources/SidebarWorkspaceRowsMeasurement.swift new file mode 100644 index 000000000000..6488a272c182 --- /dev/null +++ b/Sources/SidebarWorkspaceRowsMeasurement.swift @@ -0,0 +1,29 @@ +import CoreGraphics + +/// A single whole-content height measurement of the sidebar workspace rows, +/// keyed by the workspace row identity that produced it. +/// +/// The sidebar sizes the empty drop/tap area below the last row to the +/// remaining viewport (`SidebarWorkspaceScrollLayout.emptyAreaHeight`) from +/// one measurement of the laid-out rows. Keying by `workspaceIds` lets a stale +/// measurement be ignored after rows are added, removed, or reordered, and +/// `isEquivalent(to:tolerance:)` dedupes sub-pixel height jitter so constant +/// agent-driven row re-renders do not write `@State` and re-feed a +/// preference/layout transaction cycle +/// (the https://github.com/manaflow-ai/cmux/issues/2586 class of livelock). +struct SidebarWorkspaceRowsMeasurement: Equatable { + let workspaceIds: [ID] + let rowsHeight: CGFloat + + nonisolated func rowsHeight(for currentWorkspaceIds: [ID]) -> CGFloat? { + guard workspaceIds == currentWorkspaceIds else { return nil } + return max(0, rowsHeight) + } + + nonisolated func isEquivalent( + to other: SidebarWorkspaceRowsMeasurement, + tolerance: CGFloat = 0.5 + ) -> Bool { + workspaceIds == other.workspaceIds && abs(rowsHeight - other.rowsHeight) <= tolerance + } +} diff --git a/Sources/WindowChromeMetrics.swift b/Sources/WindowChromeMetrics.swift index e2fd085901e7..f20efd139aa5 100644 --- a/Sources/WindowChromeMetrics.swift +++ b/Sources/WindowChromeMetrics.swift @@ -76,6 +76,30 @@ enum SidebarWorkspaceScrollLayout { viewportHeight: CGFloat, insets: SidebarWorkspaceScrollInsets ) -> CGFloat { - max(0, viewportHeight - insets.total) + return max(0, viewportHeight - insets.total) + } + + /// Height of the empty drop/tap area placed below the last workspace row. + /// + /// The area fills the remaining viewport (so the content fills the visible + /// height when the rows fit) but is clamped to `0` once the rows already + /// reach or exceed `contentMinHeight`. Sizing it to this finite remainder — + /// rather than `maxHeight: .infinity` — is what keeps the document view + /// from perpetually overflowing, so the overlay scroller stays hidden when + /// there is nothing to scroll + /// (https://github.com/manaflow-ai/cmux/issues/3241). + /// + /// - Parameters: + /// - contentMinHeight: The viewport height available to the scroll content. + /// - rowsHeight: The measured height of the laid-out rows, or `nil` when + /// no measurement is available yet (in which case the area collapses to + /// `0` and the content's `minHeight` frame still fills the viewport). + /// - Returns: The non-negative height for the empty area. + nonisolated static func emptyAreaHeight( + contentMinHeight: CGFloat, + rowsHeight: CGFloat? + ) -> CGFloat { + guard let rowsHeight, rowsHeight > 0 else { return 0 } + return max(0, contentMinHeight - rowsHeight) } } diff --git a/cmux.xcodeproj/project.pbxproj b/cmux.xcodeproj/project.pbxproj index a1fd3cd0bd1f..bcaca40b6d76 100644 --- a/cmux.xcodeproj/project.pbxproj +++ b/cmux.xcodeproj/project.pbxproj @@ -560,6 +560,8 @@ B9000130A1B2C3D4E5F60719 /* SidebarPullRequestInteractivityUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9000131A1B2C3D4E5F60719 /* SidebarPullRequestInteractivityUITests.swift */; }; B8F266236A1A3D9A45BD840F /* SidebarResizeUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 818DBCD4AB69EB72573E8138 /* SidebarResizeUITests.swift */; }; C0DE35010000000000000001 /* SidebarScrim.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0DE35010000000000000002 /* SidebarScrim.swift */; }; + C9A57511C9A57511C9A57511 /* SidebarScrollViewConfigurator.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9A57512C9A57512C9A57512 /* SidebarScrollViewConfigurator.swift */; }; + C9A57513C9A57513C9A57513 /* SidebarScrollViewConfiguratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9A57514C9A57514C9A57514 /* SidebarScrollViewConfiguratorTests.swift */; }; E62155868BB29FEB5DAAAF25 /* SidebarSelectionState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9AD52285508B1D6A9875E7B3 /* SidebarSelectionState.swift */; }; F57072635F25EBCA741E125D /* SidebarState.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1614EAD3CCF70A177A51BD1 /* SidebarState.swift */; }; D7AB34300000000000000105 /* SidebarTabDropIndicatorPredicateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7AB34300000000000000106 /* SidebarTabDropIndicatorPredicateTests.swift */; }; @@ -575,6 +577,9 @@ C9A57109C9A57109C9A57109 /* SidebarWorkspaceGroupingMetrics.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9A5710AC9A5710AC9A5710A /* SidebarWorkspaceGroupingMetrics.swift */; }; C9A57201C9A57201C9A57201 /* SidebarWorkspaceRenderItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9A57202C9A57202C9A57202 /* SidebarWorkspaceRenderItem.swift */; }; D35450010000000000000001 /* SidebarWorkspaceRowHoverTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = D35450020000000000000002 /* SidebarWorkspaceRowHoverTracker.swift */; }; + C9A57501C9A57501C9A57501 /* SidebarWorkspaceRowsHeightPreferenceKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9A57502C9A57502C9A57502 /* SidebarWorkspaceRowsHeightPreferenceKey.swift */; }; + C9A57503C9A57503C9A57503 /* SidebarWorkspaceRowsMeasurement.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9A57504C9A57504C9A57504 /* SidebarWorkspaceRowsMeasurement.swift */; }; + C9A57505C9A57505C9A57505 /* SidebarWorkspaceScrollLayoutTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9A57506C9A57506C9A57506 /* SidebarWorkspaceScrollLayoutTests.swift */; }; C0DE56010000000000000001 /* SidebarWorkspaceSelectionAnchorPolicyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0DE56010000000000000002 /* SidebarWorkspaceSelectionAnchorPolicyTests.swift */; }; 988C6A036BA56EA5759A95A0 /* SidebarWorkspaceSnapshotRefreshPolicy.swift in Sources */ = {isa = PBXBuildFile; fileRef = D50D9BCE46701FBA91C2EFB6 /* SidebarWorkspaceSnapshotRefreshPolicy.swift */; }; 62270F3DCECB4787D789CCE3 /* SidebarWorkspaceSnapshotRefreshPolicyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F016B5C09357B3226FA2E014 /* SidebarWorkspaceSnapshotRefreshPolicyTests.swift */; }; @@ -1292,6 +1297,8 @@ B9000131A1B2C3D4E5F60719 /* SidebarPullRequestInteractivityUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarPullRequestInteractivityUITests.swift; sourceTree = ""; }; 818DBCD4AB69EB72573E8138 /* SidebarResizeUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarResizeUITests.swift; sourceTree = ""; }; C0DE35010000000000000002 /* SidebarScrim.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarScrim.swift; sourceTree = ""; }; + C9A57512C9A57512C9A57512 /* SidebarScrollViewConfigurator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarScrollViewConfigurator.swift; sourceTree = ""; }; + C9A57514C9A57514C9A57514 /* SidebarScrollViewConfiguratorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarScrollViewConfiguratorTests.swift; sourceTree = ""; }; 9AD52285508B1D6A9875E7B3 /* SidebarSelectionState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarSelectionState.swift; sourceTree = ""; }; D1614EAD3CCF70A177A51BD1 /* SidebarState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Sidebar/SidebarState.swift; sourceTree = ""; }; D7AB34300000000000000106 /* SidebarTabDropIndicatorPredicateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarTabDropIndicatorPredicateTests.swift; sourceTree = ""; }; @@ -1307,6 +1314,9 @@ C9A5710AC9A5710AC9A5710A /* SidebarWorkspaceGroupingMetrics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarWorkspaceGroupingMetrics.swift; sourceTree = ""; }; C9A57202C9A57202C9A57202 /* SidebarWorkspaceRenderItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarWorkspaceRenderItem.swift; sourceTree = ""; }; D35450020000000000000002 /* SidebarWorkspaceRowHoverTracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Sidebar/SidebarWorkspaceRowHoverTracker.swift; sourceTree = ""; }; + C9A57502C9A57502C9A57502 /* SidebarWorkspaceRowsHeightPreferenceKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarWorkspaceRowsHeightPreferenceKey.swift; sourceTree = ""; }; + C9A57504C9A57504C9A57504 /* SidebarWorkspaceRowsMeasurement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarWorkspaceRowsMeasurement.swift; sourceTree = ""; }; + C9A57506C9A57506C9A57506 /* SidebarWorkspaceScrollLayoutTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarWorkspaceScrollLayoutTests.swift; sourceTree = ""; }; C0DE56010000000000000002 /* SidebarWorkspaceSelectionAnchorPolicyTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarWorkspaceSelectionAnchorPolicyTests.swift; sourceTree = ""; }; D50D9BCE46701FBA91C2EFB6 /* SidebarWorkspaceSnapshotRefreshPolicy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Sidebar/SidebarWorkspaceSnapshotRefreshPolicy.swift; sourceTree = ""; }; F016B5C09357B3226FA2E014 /* SidebarWorkspaceSnapshotRefreshPolicyTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarWorkspaceSnapshotRefreshPolicyTests.swift; sourceTree = ""; }; @@ -1719,6 +1729,9 @@ C9A5710AC9A5710AC9A5710A /* SidebarWorkspaceGroupingMetrics.swift */, D5037010000000000000002 /* RenderableSystemSymbol.swift */, C9A57202C9A57202C9A57202 /* SidebarWorkspaceRenderItem.swift */, + C9A57512C9A57512C9A57512 /* SidebarScrollViewConfigurator.swift */, + C9A57502C9A57502C9A57502 /* SidebarWorkspaceRowsHeightPreferenceKey.swift */, + C9A57504C9A57504C9A57504 /* SidebarWorkspaceRowsMeasurement.swift */, C9A5720CC9A5720CC9A5720C /* TabItemView+WorkspaceGroups.swift */, C9A5720AC9A5720AC9A5720A /* VerticalTabsSidebar+WorkspaceGroups.swift */, C9A57204C9A57204C9A57204 /* WorkspaceGroupMenuSnapshot.swift */, @@ -2176,6 +2189,8 @@ 71F8ED92A4B55D34BE6A0668 /* WorkspaceSplitStartupCommandTests.swift */, EF7347934AB1BD387686EE43 /* WorkspaceActionDispatcherTests.swift */, F016B5C09357B3226FA2E014 /* SidebarWorkspaceSnapshotRefreshPolicyTests.swift */, + C9A57514C9A57514C9A57514 /* SidebarScrollViewConfiguratorTests.swift */, + C9A57506C9A57506C9A57506 /* SidebarWorkspaceScrollLayoutTests.swift */, C0DEF0B30000000000000002 /* KeyboardShortcutSettingsFileStoreMigrationTests.swift */, E3337002E3337002E3337002 /* KeyboardShortcutSettingsFileStoreStartupTests.swift */, C34670020000000000000002 /* KeyboardShortcutContextTests.swift */, @@ -2972,6 +2987,7 @@ EA1F00000000000000000001 /* SidebarPathFormatter.swift in Sources */, C0DEF0A30000000000000001 /* SidebarPortDisplayText.swift in Sources */, C0DE35010000000000000001 /* SidebarScrim.swift in Sources */, + C9A57511C9A57511C9A57511 /* SidebarScrollViewConfigurator.swift in Sources */, E62155868BB29FEB5DAAAF25 /* SidebarSelectionState.swift in Sources */, F57072635F25EBCA741E125D /* SidebarState.swift in Sources */, C9A57103C9A57103C9A57103 /* SidebarWorkspaceGroupConfigOpener.swift in Sources */, @@ -2982,6 +2998,8 @@ C9A57109C9A57109C9A57109 /* SidebarWorkspaceGroupingMetrics.swift in Sources */, C9A57201C9A57201C9A57201 /* SidebarWorkspaceRenderItem.swift in Sources */, D35450010000000000000001 /* SidebarWorkspaceRowHoverTracker.swift in Sources */, + C9A57501C9A57501C9A57501 /* SidebarWorkspaceRowsHeightPreferenceKey.swift in Sources */, + C9A57503C9A57503C9A57503 /* SidebarWorkspaceRowsMeasurement.swift in Sources */, 988C6A036BA56EA5759A95A0 /* SidebarWorkspaceSnapshotRefreshPolicy.swift in Sources */, A5001226 /* SocketControlMode+Display.swift in Sources */, E3309A0D /* SplitEqualizer.swift in Sources */, @@ -3301,11 +3319,13 @@ 385C6BA7E78DB87460E5D930 /* SidebarMarkdownRendererTests.swift in Sources */, CB23911D7E131E8FBC9B82B6 /* SidebarOrderingTests.swift in Sources */, C0DE48000000000000000001 /* SidebarProviderMenuRegressionTests.swift in Sources */, + C9A57513C9A57513C9A57513 /* SidebarScrollViewConfiguratorTests.swift in Sources */, D7AB34300000000000000105 /* SidebarTabDropIndicatorPredicateTests.swift in Sources */, CA39C0304FE351A21C372429 /* SidebarWidthPolicyTests.swift in Sources */, D7AB34300000000000000005 /* SidebarWorkspaceDropPlannerTests.swift in Sources */, C135190000000000000000B1 /* SidebarWorkspaceGroupConfigOpenerTests.swift in Sources */, C9A57303C9A57303C9A57303 /* SidebarWorkspaceGroupHeaderMetricsTests.swift in Sources */, + C9A57505C9A57505C9A57505 /* SidebarWorkspaceScrollLayoutTests.swift in Sources */, C0DE56010000000000000001 /* SidebarWorkspaceSelectionAnchorPolicyTests.swift in Sources */, 62270F3DCECB4787D789CCE3 /* SidebarWorkspaceSnapshotRefreshPolicyTests.swift in Sources */, F8000000A1B2C3D4E5F60718 /* SocketControlPasswordStoreTests.swift in Sources */, diff --git a/cmuxTests/SidebarScrollViewConfiguratorTests.swift b/cmuxTests/SidebarScrollViewConfiguratorTests.swift new file mode 100644 index 000000000000..dc5271e16d11 --- /dev/null +++ b/cmuxTests/SidebarScrollViewConfiguratorTests.swift @@ -0,0 +1,78 @@ +import AppKit +import Testing + +#if canImport(cmux_DEV) +@testable import cmux_DEV +#elseif canImport(cmux) +@testable import cmux +#endif + +@MainActor +@Suite("Sidebar scroll view configurator") +struct SidebarScrollViewConfiguratorTests { + /// Counts every setter invocation, including same-value writes — a + /// same-value `scrollerStyle`/scroller write still re-tiles AppKit's + /// overlay scrollers and can cancel an in-flight fade, which is the + /// stuck-knob mechanism this guards against. + private final class SetterCountingScrollView: NSScrollView { + var configPropertyWrites = 0 + + override var hasHorizontalScroller: Bool { + get { super.hasHorizontalScroller } + set { + configPropertyWrites += 1 + super.hasHorizontalScroller = newValue + } + } + + override var hasVerticalScroller: Bool { + get { super.hasVerticalScroller } + set { + configPropertyWrites += 1 + super.hasVerticalScroller = newValue + } + } + + override var autohidesScrollers: Bool { + get { super.autohidesScrollers } + set { + configPropertyWrites += 1 + super.autohidesScrollers = newValue + } + } + + override var scrollerStyle: NSScroller.Style { + get { super.scrollerStyle } + set { + configPropertyWrites += 1 + super.scrollerStyle = newValue + } + } + } + + @Test func firstApplyEstablishesOverlayConfiguration() { + let scrollView = SetterCountingScrollView(frame: NSRect(x: 0, y: 0, width: 200, height: 400)) + + SidebarScrollViewConfigurator.apply(to: scrollView) + + #expect(!scrollView.hasHorizontalScroller) + #expect(scrollView.hasVerticalScroller) + #expect(scrollView.autohidesScrollers) + #expect(scrollView.scrollerStyle == .overlay) + } + + @Test func reapplyToConfiguredScrollViewWritesNothing() { + // The resolver re-applies on every SwiftUI update of the sidebar. A + // re-apply must be a pure no-op: any property write (same-value + // included) re-tiles the overlay scrollers and can cancel an + // in-flight knob fade without rescheduling it, leaving the knob + // permanently visible. + let scrollView = SetterCountingScrollView(frame: NSRect(x: 0, y: 0, width: 200, height: 400)) + SidebarScrollViewConfigurator.apply(to: scrollView) + + scrollView.configPropertyWrites = 0 + SidebarScrollViewConfigurator.apply(to: scrollView) + + #expect(scrollView.configPropertyWrites == 0) + } +} diff --git a/cmuxTests/SidebarWorkspaceScrollLayoutTests.swift b/cmuxTests/SidebarWorkspaceScrollLayoutTests.swift new file mode 100644 index 000000000000..679a46c7a09c --- /dev/null +++ b/cmuxTests/SidebarWorkspaceScrollLayoutTests.swift @@ -0,0 +1,84 @@ +import CoreGraphics +import Testing + +#if canImport(cmux_DEV) +@testable import cmux_DEV +#elseif canImport(cmux) +@testable import cmux +#endif + +@MainActor +@Suite("Sidebar workspace scroll layout") +struct SidebarWorkspaceScrollLayoutTests { + @Test func unmeasuredRowsCollapseEmptyAreaWithoutForcingOverflow() { + // Before a measurement arrives, the empty area collapses to 0. The + // content's `minHeight` frame still fills the viewport, so the document + // view does not overflow and the overlay scroller stays hidden. + let contentMinHeight: CGFloat = 480 + let emptyAreaHeight = SidebarWorkspaceScrollLayout.emptyAreaHeight( + contentMinHeight: contentMinHeight, + rowsHeight: nil + ) + + #expect(abs(emptyAreaHeight) <= 0.001) + // The content frame is pinned to contentMinHeight, so it never exceeds + // the viewport: no overflow, overlay scroller stays hidden. + #expect(max(contentMinHeight, emptyAreaHeight) <= contentMinHeight) + } + + @Test func rowsMeasurementIgnoresStaleWorkspaceIds() { + let measurement = SidebarWorkspaceRowsMeasurement( + workspaceIds: ["a", "b"], + rowsHeight: 240 + ) + + #expect(measurement.rowsHeight(for: ["b", "c"]) == nil) + #expect(abs((measurement.rowsHeight(for: ["a", "b"]) ?? -1) - 240) <= 0.001) + } + + @Test func rowsMeasurementDedupesSubPixelJitterForSameWorkspaceIds() { + // The livelock-safety invariant: the single whole-content measurement + // is deduped so sub-pixel height jitter from constant agent-driven row + // re-renders does NOT write @State, so it cannot re-feed a + // preference/layout transaction cycle (the #2586 class of bug). + let base = SidebarWorkspaceRowsMeasurement(workspaceIds: ["a", "b"], rowsHeight: 240) + let jittered = SidebarWorkspaceRowsMeasurement(workspaceIds: ["a", "b"], rowsHeight: 240.3) + let moved = SidebarWorkspaceRowsMeasurement(workspaceIds: ["a", "b"], rowsHeight: 256) + let differentRows = SidebarWorkspaceRowsMeasurement(workspaceIds: ["a"], rowsHeight: 240) + + #expect(base.isEquivalent(to: jittered)) + #expect(!base.isEquivalent(to: moved)) + #expect(!base.isEquivalent(to: differentRows)) + } + + @Test func emptyAreaFillsOnlyRemainingViewportSpaceWhenRowsFit() { + let contentMinHeight = SidebarWorkspaceScrollLayout.contentMinHeight( + viewportHeight: 720, + insets: SidebarWorkspaceScrollInsets(top: 28, bottom: 48) + ) + let rowsHeight: CGFloat = 96 + let emptyAreaHeight = SidebarWorkspaceScrollLayout.emptyAreaHeight( + contentMinHeight: contentMinHeight, + rowsHeight: rowsHeight + ) + + #expect(abs(emptyAreaHeight - (contentMinHeight - rowsHeight)) <= 0.001) + // Rows + filled empty area exactly equals the viewport: content fits, + // so the overlay scroller stays hidden (the #3241 phantom-scrollbar fix). + #expect(abs((rowsHeight + emptyAreaHeight) - contentMinHeight) <= 0.001) + } + + @Test func emptyAreaCollapsesWhenRowsAlreadyOverflowViewport() { + let contentMinHeight: CGFloat = 300 + let rowsHeight: CGFloat = 420 + let emptyAreaHeight = SidebarWorkspaceScrollLayout.emptyAreaHeight( + contentMinHeight: contentMinHeight, + rowsHeight: rowsHeight + ) + + #expect(abs(emptyAreaHeight) <= 0.001) + // The empty area adds nothing, so the document view stays at the rows' + // natural height and genuinely overflows the viewport — a real scroll. + #expect(rowsHeight + emptyAreaHeight > contentMinHeight) + } +} diff --git a/cmuxTests/WorkspaceGroupTests.swift b/cmuxTests/WorkspaceGroupTests.swift index b68b5620a627..bd02582aa6de 100644 --- a/cmuxTests/WorkspaceGroupTests.swift +++ b/cmuxTests/WorkspaceGroupTests.swift @@ -177,7 +177,9 @@ struct WorkspaceGroupTests { var groupMemberIds: [UUID] = [] var visibleWorkspaceIds: [UUID] = [] + var visibleRowIds: [UUID] = [] for item in items { + visibleRowIds.append(item.rowWorkspaceId) switch item { case .groupHeader(let renderedGroup, let memberWorkspaceIds) where renderedGroup.id == groupId: groupMemberIds = memberWorkspaceIds @@ -195,6 +197,11 @@ struct WorkspaceGroupTests { ]) #expect(!visibleWorkspaceIds.contains(originalIds[1])) #expect(!visibleWorkspaceIds.contains(originalIds[2])) + #expect(visibleRowIds == [ + originalIds[0], + group.anchorWorkspaceId, + originalIds[3], + ]) } @Test func groupHeaderEdgeDropUsesTopLevelIndicatorScope() throws {