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
6 changes: 3 additions & 3 deletions .github/swift-file-length-budget.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
20530 CLI/cmux.swift
17229 Sources/TerminalController.swift
16020 Sources/ContentView.swift
14471 Sources/AppDelegate.swift
14475 Sources/AppDelegate.swift
13932 Sources/Workspace.swift
13409 Sources/GhosttyTerminalView.swift
10597 Sources/Panels/BrowserPanel.swift
Expand All @@ -21,7 +21,7 @@
3840 Sources/Feed/FeedPanelView.swift
3588 cmuxTests/BrowserConfigTests.swift
3145 cmuxTests/BrowserPanelTests.swift
2922 Sources/CmuxConfig.swift
2938 Sources/CmuxConfig.swift
2863 cmuxTests/WindowAndDragTests.swift
2609 Sources/SessionIndexView.swift
2491 Sources/Panels/CmuxWebView.swift
Expand All @@ -33,7 +33,7 @@
2026 cmuxTests/CJKIMEInputTests.swift
1949 Sources/Panels/BrowserWebAuthnSupport.swift
1879 Sources/FileExplorerView.swift
1846 cmuxTests/CmuxConfigTests.swift
1899 cmuxTests/CmuxConfigTests.swift
1826 Sources/SessionIndexStore.swift
1784 cmuxTests/ShortcutAndCommandPaletteTests.swift
1684 Sources/KeyboardShortcutSettingsFileStore.swift
Expand Down
12 changes: 12 additions & 0 deletions GhosttyTabs.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
D0B1000CA1B2C3D4E5F60001 /* CmuxWebViewDragRoutingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0B1000DA1B2C3D4E5F60001 /* CmuxWebViewDragRoutingTests.swift */; };
D0B1000EA1B2C3D4E5F60001 /* BrowserPaneDropRoutingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0B1000FA1B2C3D4E5F60001 /* BrowserPaneDropRoutingTests.swift */; };
D0B10010A1B2C3D4E5F60001 /* BonsplitTabBarDebug.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0B10011A1B2C3D4E5F60001 /* BonsplitTabBarDebug.swift */; };
D7AB34300000000000000001 /* SidebarDropPlanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7AB34300000000000000002 /* SidebarDropPlanner.swift */; };
D7AB34300000000000000003 /* SidebarBonsplitTabWorkspaceDropOverlay.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7AB34300000000000000004 /* SidebarBonsplitTabWorkspaceDropOverlay.swift */; };
D7AB34300000000000000005 /* SidebarWorkspaceDropPlannerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7AB34300000000000000006 /* SidebarWorkspaceDropPlannerTests.swift */; };
5EDB6027B346C46521A93C74 /* CMUXAuthCore in Frameworks */ = {isa = PBXBuildFile; productRef = 29813FE5A6CBC1019289A251 /* CMUXAuthCore */; };
AA11BB22CC33DD44EE550001 /* CMUXWorkstream in Frameworks */ = {isa = PBXBuildFile; productRef = AA11BB22CC33DD44EE550002 /* CMUXWorkstream */; };
FEED0000000000000000F002 /* FeedCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = FEED0000000000000000F001 /* FeedCoordinator.swift */; };
Expand Down Expand Up @@ -374,6 +377,7 @@
43430FA5929121E2EAAB3091 /* AuthEnvironment.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = AuthEnvironment.swift; sourceTree = "<group>"; };
491751CE2321474474F27DCF /* TerminalControllerSocketSecurityTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TerminalControllerSocketSecurityTests.swift; sourceTree = "<group>"; };
51D800000000000000000002 /* SidebarIdentifierFormattingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarIdentifierFormattingTests.swift; sourceTree = "<group>"; };
D7AB34300000000000000006 /* SidebarWorkspaceDropPlannerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarWorkspaceDropPlannerTests.swift; sourceTree = "<group>"; };
9C1BEA3D2E6F49709A71C021 /* TerminalControllerSocketWriteTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TerminalControllerSocketWriteTests.swift; sourceTree = "<group>"; };
58C7B1B978620BE162CC057E /* BrowserPanelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowserPanelTests.swift; sourceTree = "<group>"; };
5B1EA8948C5F126FE63CFB4E /* AuthSettingsStore.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = AuthSettingsStore.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -403,6 +407,8 @@
A5001012 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
C3408A000000000000000002 /* ContentView+RightSidebarCommandPalette.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ContentView+RightSidebarCommandPalette.swift"; sourceTree = "<group>"; };
D7AB00000000000000000004 /* ContentView+MoveTabToNewWorkspace.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ContentView+MoveTabToNewWorkspace.swift"; sourceTree = "<group>"; };
D7AB34300000000000000002 /* SidebarDropPlanner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Sidebar/SidebarDropPlanner.swift; sourceTree = "<group>"; };
D7AB34300000000000000004 /* SidebarBonsplitTabWorkspaceDropOverlay.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Sidebar/SidebarBonsplitTabWorkspaceDropOverlay.swift; sourceTree = "<group>"; };
D0C0D0C0D0C0D0C0D0C0D002 /* DockPanelView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DockPanelView.swift; sourceTree = "<group>"; };
D0C0D0C0D0C0D0C0D0C0D004 /* DockEmptyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DockEmptyView.swift; sourceTree = "<group>"; };
C0DE32470000000000000002 /* ContentViewIdentifierCopyCommands.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentViewIdentifierCopyCommands.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -778,6 +784,8 @@
A5001012 /* ContentView.swift */,
C3408A000000000000000002 /* ContentView+RightSidebarCommandPalette.swift */,
D7AB00000000000000000004 /* ContentView+MoveTabToNewWorkspace.swift */,
D7AB34300000000000000002 /* SidebarDropPlanner.swift */,
D7AB34300000000000000004 /* SidebarBonsplitTabWorkspaceDropOverlay.swift */,
C0DE32470000000000000002 /* ContentViewIdentifierCopyCommands.swift */,
9960CC3992F3C44489E7627C /* WorkspaceRuntimeSettings.swift */,
243632BA1DBBA36FD46E0610 /* SidebarAppearanceSupport.swift */,
Expand Down Expand Up @@ -999,6 +1007,7 @@
1D301919B10F22B8708E8883 /* WorkspaceManualUnreadTests.swift */,
EE0171AF1F49F7547191CEE5 /* SidebarWidthPolicyTests.swift */,
51D800000000000000000002 /* SidebarIdentifierFormattingTests.swift */,
D7AB34300000000000000006 /* SidebarWorkspaceDropPlannerTests.swift */,
491751CE2321474474F27DCF /* TerminalControllerSocketSecurityTests.swift */,
9C1BEA3D2E6F49709A71C021 /* TerminalControllerSocketWriteTests.swift */,
A5A5A504A1B2C3D4E5F60718 /* TerminalNotificationQueueTests.swift */,
Expand Down Expand Up @@ -1258,6 +1267,8 @@
A5001002 /* ContentView.swift in Sources */,
C3408A000000000000000001 /* ContentView+RightSidebarCommandPalette.swift in Sources */,
D7AB00000000000000000003 /* ContentView+MoveTabToNewWorkspace.swift in Sources */,
D7AB34300000000000000001 /* SidebarDropPlanner.swift in Sources */,
D7AB34300000000000000003 /* SidebarBonsplitTabWorkspaceDropOverlay.swift in Sources */,
C0DE32470000000000000001 /* ContentViewIdentifierCopyCommands.swift in Sources */,
619D509BC9B1EA946CBD6A8A /* WorkspaceRuntimeSettings.swift in Sources */,
211A75777F433ED8BA5AE208 /* SidebarAppearanceSupport.swift in Sources */,
Expand Down Expand Up @@ -1514,6 +1525,7 @@
0F2C25F9170130F8DC09DD1B /* WorkspaceManualUnreadTests.swift in Sources */,
CA39C0304FE351A21C372429 /* SidebarWidthPolicyTests.swift in Sources */,
51D800000000000000000001 /* SidebarIdentifierFormattingTests.swift in Sources */,
D7AB34300000000000000005 /* SidebarWorkspaceDropPlannerTests.swift in Sources */,
8C4BBF2DEF6DF93F395A9EE7 /* TerminalControllerSocketSecurityTests.swift in Sources */,
9C1BEA3D2E6F49709A71C020 /* TerminalControllerSocketWriteTests.swift in Sources */,
A5A5A503A1B2C3D4E5F60718 /* TerminalNotificationQueueTests.swift in Sources */,
Expand Down
10 changes: 7 additions & 3 deletions Sources/AppDelegate+MoveTabToNewWorkspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ extension AppDelegate {
title: String? = nil,
focus: Bool = true,
focusWindow: Bool = true,
placementOverride: NewWorkspacePlacement? = nil
placementOverride: NewWorkspacePlacement? = nil,
insertionIndexOverride: Int? = nil
) -> SurfaceNewWorkspaceMoveResult? {
guard let located = locateBonsplitSurface(tabId: tabId) else { return nil }
return moveSurfaceToNewWorkspace(
Expand All @@ -41,7 +42,8 @@ extension AppDelegate {
title: title,
focus: focus,
focusWindow: focusWindow,
placementOverride: placementOverride
placementOverride: placementOverride,
insertionIndexOverride: insertionIndexOverride
)
}

Expand All @@ -52,7 +54,8 @@ extension AppDelegate {
title: String? = nil,
focus: Bool = true,
focusWindow: Bool = true,
placementOverride: NewWorkspacePlacement? = nil
placementOverride: NewWorkspacePlacement? = nil,
insertionIndexOverride: Int? = nil
) -> SurfaceNewWorkspaceMoveResult? {
guard let source = locateSurface(surfaceId: panelId),
let sourceWorkspace = source.tabManager.tabs.first(where: { $0.id == source.workspaceId }),
Expand All @@ -78,6 +81,7 @@ extension AppDelegate {
title: destinationTitle,
select: false,
placementOverride: placementOverride,
insertionIndexOverride: insertionIndexOverride,
focusIntent: activationIntent
) else {
rollbackDetachedSurface(
Expand Down
172 changes: 33 additions & 139 deletions Sources/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10106,6 +10106,27 @@ struct VerticalTabsSidebar: View {
}
.padding(.vertical, SidebarWorkspaceListMetrics.rowVerticalPadding)
.frame(maxWidth: .infinity, alignment: .leading)
.overlayPreferenceValue(SidebarWorkspaceRowFramePreferenceKey.self) { anchors in
GeometryReader { proxy in
SidebarBonsplitTabWorkspaceDropOverlay(
tabManager: tabManager,
selectedTabIds: $selectedTabIds,
lastSidebarSelectionIndex: $lastSidebarSelectionIndex,
dropIndicator: $dropIndicator,
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]
)
}
)
}
}
}

private func workspaceRow(
Expand Down Expand Up @@ -10196,6 +10217,9 @@ 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]
}
}

private func debugShortSidebarTabId(_ id: UUID?) -> String {
Expand All @@ -10212,6 +10236,14 @@ private struct SidebarWorkspaceRowIdsPreferenceKey: PreferenceKey {
}
}

private struct SidebarWorkspaceRowFramePreferenceKey: PreferenceKey {
static let defaultValue: [UUID: Anchor<CGRect>] = [:]

static func reduce(value: inout [UUID: Anchor<CGRect>], nextValue: () -> [UUID: Anchor<CGRect>]) {
value.merge(nextValue()) { _, next in next }
}
}

enum ShortcutHintModifierPolicy {
static let intentionalHoldDelay: TimeInterval = 0.30

Expand Down Expand Up @@ -13639,7 +13671,7 @@ private struct TabItemView: View, Equatable {
}

private var showsCenteredTopDropIndicator: Bool {
guard draggedTabId != nil, let indicator = dropIndicator else { return false }
guard let indicator = dropIndicator else { return false }
if indicator.tabId == tab.id && indicator.edge == .top {
return true
}
Expand Down Expand Up @@ -14601,144 +14633,6 @@ private struct SidebarMetadataMarkdownBlockRow: View {
}
}

enum SidebarDropEdge: Equatable {
case top
case bottom
}

struct SidebarDropIndicator: Equatable {
let tabId: UUID?
let edge: SidebarDropEdge
}

enum SidebarDropPlanner {
static func indicator(
draggedTabId: UUID?,
targetTabId: UUID?,
tabIds: [UUID],
pinnedTabIds: Set<UUID>,
pointerY: CGFloat? = nil,
targetHeight: CGFloat? = nil
) -> SidebarDropIndicator? {
guard tabIds.count > 1, let draggedTabId else { return nil }
guard let fromIndex = tabIds.firstIndex(of: draggedTabId) else { return nil }

let insertionPosition: Int
if let targetTabId {
guard let targetTabIndex = tabIds.firstIndex(of: targetTabId) else { return nil }
let edge: SidebarDropEdge
if let pointerY, let targetHeight {
edge = edgeForPointer(locationY: pointerY, targetHeight: targetHeight)
} else {
edge = preferredEdge(fromIndex: fromIndex, targetTabId: targetTabId, tabIds: tabIds)
}
insertionPosition = (edge == .bottom) ? targetTabIndex + 1 : targetTabIndex
} else {
insertionPosition = tabIds.count
}

let legalInsertionPosition = legalInsertionPosition(
draggedTabId: draggedTabId,
proposedInsertionPosition: insertionPosition,
tabIds: tabIds,
pinnedTabIds: pinnedTabIds
)
let legalTargetIndex = resolvedTargetIndex(
from: fromIndex,
insertionPosition: legalInsertionPosition,
totalCount: tabIds.count
)
guard legalTargetIndex != fromIndex else { return nil }
return indicatorForInsertionPosition(legalInsertionPosition, tabIds: tabIds)
}

static func targetIndex(
draggedTabId: UUID,
targetTabId: UUID?,
indicator: SidebarDropIndicator?,
tabIds: [UUID],
pinnedTabIds: Set<UUID>
) -> Int? {
guard let fromIndex = tabIds.firstIndex(of: draggedTabId) else { return nil }

let insertionPosition: Int
if let indicator, let indicatorInsertion = insertionPositionForIndicator(indicator, tabIds: tabIds) {
insertionPosition = indicatorInsertion
} else if let targetTabId {
guard let targetTabIndex = tabIds.firstIndex(of: targetTabId) else { return nil }
let edge = (indicator?.tabId == targetTabId)
? (indicator?.edge ?? preferredEdge(fromIndex: fromIndex, targetTabId: targetTabId, tabIds: tabIds))
: preferredEdge(fromIndex: fromIndex, targetTabId: targetTabId, tabIds: tabIds)
insertionPosition = (edge == .bottom) ? targetTabIndex + 1 : targetTabIndex
} else {
insertionPosition = tabIds.count
}

let legalInsertionPosition = legalInsertionPosition(
draggedTabId: draggedTabId,
proposedInsertionPosition: insertionPosition,
tabIds: tabIds,
pinnedTabIds: pinnedTabIds
)
return resolvedTargetIndex(from: fromIndex, insertionPosition: legalInsertionPosition, totalCount: tabIds.count)
}

private static func indicatorForInsertionPosition(_ insertionPosition: Int, tabIds: [UUID]) -> SidebarDropIndicator {
let clampedInsertion = max(0, min(insertionPosition, tabIds.count))
if clampedInsertion >= tabIds.count {
return SidebarDropIndicator(tabId: nil, edge: .bottom)
}
return SidebarDropIndicator(tabId: tabIds[clampedInsertion], edge: .top)
}

private static func insertionPositionForIndicator(_ indicator: SidebarDropIndicator, tabIds: [UUID]) -> Int? {
if let tabId = indicator.tabId {
guard let targetTabIndex = tabIds.firstIndex(of: tabId) else { return nil }
return indicator.edge == .bottom ? targetTabIndex + 1 : targetTabIndex
}
return tabIds.count
}

private static func preferredEdge(fromIndex: Int, targetTabId: UUID, tabIds: [UUID]) -> SidebarDropEdge {
guard let targetIndex = tabIds.firstIndex(of: targetTabId) else { return .top }
return fromIndex < targetIndex ? .bottom : .top
}

private static func legalInsertionPosition(
draggedTabId: UUID,
proposedInsertionPosition: Int,
tabIds: [UUID],
pinnedTabIds: Set<UUID>
) -> Int {
let clampedInsertion = max(0, min(proposedInsertionPosition, tabIds.count))
guard !pinnedTabIds.isEmpty else { return clampedInsertion }

let pinnedCount = tabIds.reduce(into: 0) { count, tabId in
if pinnedTabIds.contains(tabId) {
count += 1
}
}
guard pinnedCount > 0 else { return clampedInsertion }

if pinnedTabIds.contains(draggedTabId) {
return min(clampedInsertion, pinnedCount)
}
return max(clampedInsertion, pinnedCount)
}

static func edgeForPointer(locationY: CGFloat, targetHeight: CGFloat) -> SidebarDropEdge {
guard targetHeight > 0 else { return .top }
let clampedY = min(max(locationY, 0), targetHeight)
return clampedY < (targetHeight / 2) ? .top : .bottom
}

private static func resolvedTargetIndex(from sourceIndex: Int, insertionPosition: Int, totalCount: Int) -> Int {
let clampedInsertion = max(0, min(insertionPosition, totalCount))
let adjusted = clampedInsertion > sourceIndex ? clampedInsertion - 1 : clampedInsertion
return max(0, min(adjusted, max(0, totalCount - 1)))
}
}

enum SidebarAutoScrollDirection: Equatable {
case up
case down
Expand Down
Loading
Loading