Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
163 changes: 102 additions & 61 deletions Sources/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10447,6 +10447,9 @@ struct VerticalTabsSidebar: View {
)
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
@ObservedObject private var keyboardShortcutSettingsObserver = KeyboardShortcutSettingsObserver.shared
@State var dragState = SidebarDragState()
// Bonsplit tab drags arrive through AppKit pasteboard callbacks, not
// `SidebarDragState`, so they need a separate transient collection flag.
@State private var isBonsplitWorkspaceDropTargetCollectionActive = false
// Freezes `showsModifierShortcutHints` for the workspace whose context menu
// is open. Set on the row's contextMenu.onAppear and cleared on
// .onDisappear so modifier-key transitions don't flip the badges on the
Expand Down Expand Up @@ -10866,6 +10869,7 @@ struct VerticalTabsSidebar: View {
.onAppear {
modifierKeyMonitor.start()
dragState.clearDrag()
isBonsplitWorkspaceDropTargetCollectionActive = false
// Defensive reset: if a prior simulation died without running
// its teardown (sidebar unmounted mid-loop, app crash, etc.) the
// @State SidebarDragState could carry isSimulated=true into a
Expand All @@ -10884,6 +10888,7 @@ struct VerticalTabsSidebar: View {
dragAutoScrollController.stop()
dragFailsafeMonitor.stop()
dragState.clearDrag()
isBonsplitWorkspaceDropTargetCollectionActive = false
// Clear the simulator flag too so a re-mounted sidebar doesn't
// inherit a stale bypass and skip the real-drag failsafe monitor.
dragState.isSimulated = false
Expand Down Expand Up @@ -12204,90 +12209,119 @@ struct VerticalTabsSidebar: View {
.frame(minHeight: minHeight, alignment: .top)
}

@ViewBuilder
private func workspaceRows(renderContext: WorkspaceListRenderContext) -> some View {
let renderItems = SidebarWorkspaceRenderItem.renderItems(
tabs: renderContext.tabs,
groupsById: renderContext.workspaceGroupById
)
let shouldCollectWorkspaceDropTargets = SidebarDropPlanner.shouldCollectWorkspaceDropTargets(
draggedTabId: dragState.draggedTabId,
isBonsplitWorkspaceDropActive: isBonsplitWorkspaceDropTargetCollectionActive
)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
// LazyVStack is safe here because `dragState` is @Observable:
// drag mutations at 60fps invalidate only the rows/overlays that
// read them, never this sidebar body. See SidebarDragState and
// https://github.com/manaflow-ai/cmux/issues/2586.
return LazyVStack(spacing: tabRowSpacing) {
let rows = LazyVStack(spacing: tabRowSpacing) {
ForEach(renderItems, id: \.id) { item in
switch item {
case .groupHeader(let group, let memberWorkspaceIds):
sidebarWorkspaceGroupHeader(
group: group,
memberWorkspaceIds: memberWorkspaceIds,
renderContext: renderContext
renderContext: renderContext,
shouldCollectWorkspaceDropTargets: shouldCollectWorkspaceDropTargets
)
case .workspace(let tab):
workspaceRow(tab, renderContext: renderContext)
workspaceRow(
tab,
renderContext: renderContext,
shouldCollectWorkspaceDropTargets: shouldCollectWorkspaceDropTargets
)
}
}
}
.padding(.vertical, SidebarWorkspaceListMetrics.rowVerticalPadding)
.frame(maxWidth: .infinity, alignment: .leading)
.overlayPreferenceValue(SidebarWorkspaceRowFramePreferenceKey.self) { anchors in
GeometryReader { proxy in
SidebarBonsplitTabWorkspaceDropOverlay(
currentSelectedTabId: {
tabManager.selectedTabId
},
sidebarIndexForTabId: { workspaceId in
tabManager.tabs.firstIndex { $0.id == workspaceId }
},
moveToExistingWorkspace: { workspaceId, transfer in
guard let app = AppDelegate.shared else {
return false
}
if let source = app.locateBonsplitSurface(tabId: transfer.tab.id),
source.workspaceId == workspaceId {
return true
}
return app.moveBonsplitTab(
tabId: transfer.tab.id,
toWorkspace: workspaceId,
focus: true,
focusWindow: true
)
},
moveToNewWorkspace: { insertionIndex, transfer in
guard let app = AppDelegate.shared,
let result = app.moveBonsplitTabToNewWorkspace(
tabId: transfer.tab.id,
destinationManager: tabManager,
focus: true,
focusWindow: true,
insertionIndexOverride: insertionIndex
) else {
return nil
}
return result.destinationWorkspaceId
},
selectedTabIds: $selectedTabIds,
lastSidebarSelectionIndex: $lastSidebarSelectionIndex,
dropIndicator: dropIndicatorBinding,
Comment thread
austinywang marked this conversation as resolved.
Resolved
updateAutoscroll: {
dragAutoScrollController.updateFromDragLocation()
},
targets: renderContext.tabs.compactMap { tab in
guard let anchor = anchors[tab.id] else { return nil }
return SidebarDropPlanner.WorkspaceDropTarget(
workspaceId: tab.id,
isPinned: tab.isPinned,
frame: proxy[anchor]
)
}
)

rows
.overlayPreferenceValue(SidebarWorkspaceRowFramePreferenceKey.self) { anchors in
GeometryReader { proxy in
bonsplitWorkspaceDropOverlay(
targets: shouldCollectWorkspaceDropTargets
? renderContext.tabs.compactMap { tab in
guard let anchor = anchors[tab.id] else { return nil }
return SidebarDropPlanner.WorkspaceDropTarget(
workspaceId: tab.id,
isPinned: tab.isPinned,
frame: proxy[anchor]
)
}
: []
)
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
}

private func bonsplitWorkspaceDropOverlay(
targets: [SidebarDropPlanner.WorkspaceDropTarget]
) -> some View {
SidebarBonsplitTabWorkspaceDropOverlay(
currentSelectedTabId: {
tabManager.selectedTabId
},
sidebarIndexForTabId: { workspaceId in
tabManager.tabs.firstIndex { $0.id == workspaceId }
},
moveToExistingWorkspace: { workspaceId, transfer in
guard let app = AppDelegate.shared else {
return false
}
if let source = app.locateBonsplitSurface(tabId: transfer.tab.id),
source.workspaceId == workspaceId {
return true
}
return app.moveBonsplitTab(
tabId: transfer.tab.id,
toWorkspace: workspaceId,
focus: true,
focusWindow: true
)
},
moveToNewWorkspace: { insertionIndex, transfer in
guard let app = AppDelegate.shared,
let result = app.moveBonsplitTabToNewWorkspace(
tabId: transfer.tab.id,
destinationManager: tabManager,
focus: true,
focusWindow: true,
insertionIndexOverride: insertionIndex
) else {
return nil
}
return result.destinationWorkspaceId
},
selectedTabIds: $selectedTabIds,
lastSidebarSelectionIndex: $lastSidebarSelectionIndex,
dropIndicator: dropIndicatorBinding,
updateAutoscroll: {
dragAutoScrollController.updateFromDragLocation()
},
setWorkspaceDropTargetCollectionActive: { isActive in
guard isBonsplitWorkspaceDropTargetCollectionActive != isActive else { return }
isBonsplitWorkspaceDropTargetCollectionActive = isActive
},
isWorkspaceDropTargetCollectionActive: isBonsplitWorkspaceDropTargetCollectionActive,
targets: targets
)
}

@ViewBuilder
private func workspaceRow(
_ tab: Workspace,
renderContext: WorkspaceListRenderContext
renderContext: WorkspaceListRenderContext,
shouldCollectWorkspaceDropTargets: Bool
) -> some View {
let index = renderContext.tabIndexById[tab.id] ?? 0
let usesSelectedContextMenuTargets = selectedTabIds.contains(tab.id)
Expand Down Expand Up @@ -12377,7 +12411,7 @@ struct VerticalTabsSidebar: View {
)
}

return TabItemView(
let row = TabItemView(
tabManager: tabManager,
notificationStore: notificationStore,
tab: tab,
Expand Down Expand Up @@ -12416,10 +12450,17 @@ struct VerticalTabsSidebar: View {
.id(tab.id)
.accessibilityIdentifier("sidebarWorkspace.\(tab.id.uuidString)")
.preference(key: SidebarWorkspaceRowIdsPreferenceKey.self, value: Set([tab.id]))
.anchorPreference(key: SidebarWorkspaceRowFramePreferenceKey.self, value: .bounds) { anchor in
[tab.id: anchor]

if shouldCollectWorkspaceDropTargets {
row
.anchorPreference(key: SidebarWorkspaceRowFramePreferenceKey.self, value: .bounds) { anchor in
[tab.id: anchor]
}
.padding(.leading, tab.groupId != nil ? SidebarWorkspaceGroupingMetrics.memberIndent : 0)
} else {
row
.padding(.leading, tab.groupId != nil ? SidebarWorkspaceGroupingMetrics.memberIndent : 0)
}
Comment thread
austinywang marked this conversation as resolved.
Resolved
.padding(.leading, tab.groupId != nil ? SidebarWorkspaceGroupingMetrics.memberIndent : 0)
}

private func debugShortSidebarTabId(_ id: UUID?) -> String {
Expand Down
Loading
Loading