Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions macos/Sources/Features/Terminal/TerminalController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,14 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
}
}

private func closeNativeTab(windowNumber: Int) {
guard let window else { return }
let candidateWindows = window.tabGroup?.windows ?? [window]
guard let targetWindow = candidateWindows.first(where: { $0.windowNumber == windowNumber }) else { return }
guard let targetController = targetWindow.windowController as? TerminalController else { return }
targetController.closeTab(nil)
}

private func moveNativeTabBefore(movingWindowNumber: Int, targetWindowNumber: Int) {
guard movingWindowNumber != targetWindowNumber else { return }
guard let window else { return }
Expand Down Expand Up @@ -1458,6 +1466,9 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
focusNativeTab: { [weak self] windowNumber in
self?.focusNativeTab(windowNumber: windowNumber)
},
closeNativeTab: { [weak self] windowNumber in
self?.closeNativeTab(windowNumber: windowNumber)
},
moveNativeTabBefore: { [weak self] moving, target in
self?.moveNativeTabBefore(movingWindowNumber: moving, targetWindowNumber: target)
},
Expand Down
2 changes: 2 additions & 0 deletions macos/Sources/Features/Terminal/TerminalWorkspaceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct TerminalWorkspaceView<ViewModel: TerminalViewModel>: View {
let openWorktreeAgent: (String, WorktrunkAgent) -> Void
let resumeSession: ((AISession) -> Void)?
let focusNativeTab: (Int) -> Void
let closeNativeTab: (Int) -> Void
let moveNativeTabBefore: (Int, Int) -> Void
let moveNativeTabAfter: (Int, Int) -> Void
let onSidebarWidthChange: (CGFloat) -> Void
Expand All @@ -36,6 +37,7 @@ struct TerminalWorkspaceView<ViewModel: TerminalViewModel>: View {
openWorktreeAgent: openWorktreeAgent,
resumeSession: resumeSession,
focusNativeTab: focusNativeTab,
closeNativeTab: closeNativeTab,
moveNativeTabBefore: moveNativeTabBefore,
moveNativeTabAfter: moveNativeTabAfter,
onSelectWorktree: { path in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class TerminalWorkspaceViewContainer<ViewModel: TerminalViewModel>: NSView {
openWorktreeAgent: @escaping (String, WorktrunkAgent) -> Void,
resumeSession: ((AISession) -> Void)? = nil,
focusNativeTab: @escaping (Int) -> Void,
closeNativeTab: @escaping (Int) -> Void,
moveNativeTabBefore: @escaping (Int, Int) -> Void,
moveNativeTabAfter: @escaping (Int, Int) -> Void,
onSidebarWidthChange: @escaping (CGFloat) -> Void,
Expand All @@ -38,6 +39,7 @@ class TerminalWorkspaceViewContainer<ViewModel: TerminalViewModel>: NSView {
openWorktreeAgent: openWorktreeAgent,
resumeSession: resumeSession,
focusNativeTab: focusNativeTab,
closeNativeTab: closeNativeTab,
moveNativeTabBefore: moveNativeTabBefore,
moveNativeTabAfter: moveNativeTabAfter,
onSidebarWidthChange: onSidebarWidthChange,
Expand Down
59 changes: 43 additions & 16 deletions macos/Sources/Features/Worktrunk/WorktrunkSidebarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct WorktrunkSidebarView: View {
let openWorktreeAgent: (String, WorktrunkAgent) -> Void
var resumeSession: ((AISession) -> Void)?
let focusNativeTab: (Int) -> Void
let closeNativeTab: (Int) -> Void
let moveNativeTabBefore: (Int, Int) -> Void
let moveNativeTabAfter: (Int, Int) -> Void
var onSelectWorktree: ((String?) -> Void)?
Expand Down Expand Up @@ -367,23 +368,27 @@ struct WorktrunkSidebarView: View {
defaultAction: defaultAction,
availableAgents: availableAgents,
alwaysVisibleWorktreePaths: alwaysVisibleWorktreePaths,
focusNativeTab: focusNativeTab,
moveBefore: moveBeforePreservingScroll,
moveAfter: moveAfterPreservingScroll,
windowNumberByWorktreePath: windowNumberByWorktreePath
)
}
focusNativeTab: focusNativeTab,
closeNativeTab: closeNativeTab,
onRemoveWorktree: { worktree in
removeWorktreeConfirm = worktree
},
moveBefore: moveBeforePreservingScroll,
moveAfter: moveAfterPreservingScroll,
windowNumberByWorktreePath: windowNumberByWorktreePath
)
}

if let last = shownTabs.last?.tab {
Rectangle()
.fill(Color.clear)
.frame(maxWidth: .infinity)
.frame(height: 1)
.contentShape(Rectangle())
.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
.listRowSeparator(.hidden)
.overlay(alignment: .center) {
if sidebarTabsEndDropTarget {
if let last = shownTabs.last?.tab {
Rectangle()
.fill(Color.clear)
.frame(maxWidth: .infinity)
.frame(height: 1)
.contentShape(Rectangle())
.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
.listRowSeparator(.hidden)
.overlay(alignment: .center) {
if sidebarTabsEndDropTarget {
SidebarInsertionIndicatorLine()
}
}
Expand Down Expand Up @@ -870,6 +875,8 @@ private struct WorktreeTabDisclosureGroup: View {
let availableAgents: [WorktrunkAgent]
let alwaysVisibleWorktreePaths: Set<String>
let focusNativeTab: (Int) -> Void
let closeNativeTab: (Int) -> Void
let onRemoveWorktree: (WorktrunkStore.Worktree) -> Void
let moveBefore: (Int, Int) -> Void
let moveAfter: (Int, Int) -> Void
let windowNumberByWorktreePath: [String: Int]
Expand Down Expand Up @@ -926,6 +933,12 @@ private struct WorktreeTabDisclosureGroup: View {
sidebarState.selection = .worktree(repoID: worktree.repositoryID, path: worktree.path)
focusNativeTab(tab.windowNumber)
},
onClose: {
closeNativeTab(tab.windowNumber)
},
onRemoveWorktree: {
onRemoveWorktree(worktree)
},
onDropBefore: { moving in
guard moving != tab.windowNumber else { return }
moveBefore(moving, tab.windowNumber)
Expand All @@ -951,6 +964,8 @@ private struct WorktreeTabRowLabel: View {
let openWorktree: (String) -> Void
let openWorktreeAgent: (String, WorktrunkAgent) -> Void
let onActivate: () -> Void
let onClose: () -> Void
let onRemoveWorktree: () -> Void
let onDropBefore: (Int) -> Void
let windowNumberByWorktreePath: [String: Int]

Expand Down Expand Up @@ -1085,6 +1100,18 @@ private struct WorktreeTabRowLabel: View {
SidebarInsertionIndicatorLine()
}
}
.contextMenu {
Button("Close Tab") {
onClose()
}
Button("Remove Worktree…") {
onRemoveWorktree()
}
.disabled(worktree.isMain)
Button("Reveal in Finder") {
NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: worktree.path)])
}
}
.onDrop(of: [UTType.fileURL.identifier], isTargeted: isDropTargetBinding) { providers in
return SidebarFileURLDrop.loadURL(from: providers) { url in
guard let url else { return }
Expand Down
Loading