Skip to content

Commit c86048e

Browse files
committed
Sync sidebar selection when switching tabs
When a tab becomes key, update the sidebar selection to match the tab's worktree root path. Previously only the reverse direction worked (clicking sidebar row focused the tab).
1 parent 2791337 commit c86048e

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

macos/Sources/Features/Terminal/TerminalController.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,6 +1528,23 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
15281528
syncWorktrunkSidebarSelectionToTabGroup(worktrunkSidebarState.selection)
15291529
}
15301530

1531+
private func syncSidebarSelectionToActiveTab() {
1532+
guard WorktrunkPreferences.worktreeTabsEnabled,
1533+
let rootPath = worktreeTabRootPath,
1534+
let appDelegate = NSApp.delegate as? AppDelegate else { return }
1535+
1536+
let store = appDelegate.worktrunkStore
1537+
for repo in store.repositories {
1538+
if store.worktrees(for: repo.id).contains(where: { $0.path == rootPath }) {
1539+
let newSelection = SidebarSelection.worktree(repoID: repo.id, path: rootPath)
1540+
guard worktrunkSidebarState.selection != newSelection else { return }
1541+
applySyncedWorktrunkSidebarSelection(newSelection)
1542+
syncWorktrunkSidebarSelectionToTabGroup(newSelection)
1543+
return
1544+
}
1545+
}
1546+
}
1547+
15311548
private func installWorktrunkTitlebar() {
15321549
guard let window else { return }
15331550
guard window.styleMask.contains(.titled) else { return }
@@ -1769,6 +1786,7 @@ class TerminalController: BaseTerminalController, TabGroupCloseCoordinator.Contr
17691786
super.windowDidBecomeKey(notification)
17701787
self.relabelTabs()
17711788
self.fixTabBar()
1789+
syncSidebarSelectionToActiveTab()
17721790
syncWorktrunkSidebarStateToTabGroup()
17731791
if let appDelegate = NSApp.delegate as? AppDelegate,
17741792
let pwd = focusedSurface?.pwd {

0 commit comments

Comments
 (0)