diff --git a/Sources/Workspace+CustomSidebarSnapshot.swift b/Sources/Workspace+CustomSidebarSnapshot.swift index cc5265b9b942..2b2298306839 100644 --- a/Sources/Workspace+CustomSidebarSnapshot.swift +++ b/Sources/Workspace+CustomSidebarSnapshot.swift @@ -134,10 +134,15 @@ extension Workspace { for tab in bonsplitController.tabs(inPane: paneId) { guard let panelId = panelIdFromSurfaceId(tab.id) else { continue } let git = reportedPanelGitBranch(panelId: panelId) + // A remote tmux window tab is a mirror container that + // `surface.focus` rejects; hand out its projected pane instead. + let focusSurfaceId = activeRemoteTmuxControlSurfaceProjection( + containerPanelID: panelId + )?.surfaceID ?? tab.id.uuid surfaces.append( CustomSidebarSurfaceSnapshot( panelId: panelId, - surfaceId: tab.id.uuid, + surfaceId: focusSurfaceId, title: tab.title, isFocused: panelId == focusedPanelId, isPinned: pinnedPanelIds.contains(panelId), diff --git a/cmuxTests/RemoteTmuxMirrorLayoutIdentityTests.swift b/cmuxTests/RemoteTmuxMirrorLayoutIdentityTests.swift index 88f25b176d1c..c08dc3455152 100644 --- a/cmuxTests/RemoteTmuxMirrorLayoutIdentityTests.swift +++ b/cmuxTests/RemoteTmuxMirrorLayoutIdentityTests.swift @@ -335,6 +335,32 @@ import Testing } } +extension RemoteTmuxMirrorLayoutIdentityTests { + @Test("custom sidebar tabs of a remote tmux window expose the focusable projected surface") + func customSidebarTabsExposeProjectedSurface() throws { + let harness = try Harness() + defer { harness.tearDown() } + + let projectedPanel = try #require(harness.singlePanePanel(tmuxPaneID: 11)) + let snapshot = harness.workspace.customSidebarWorkspaceSnapshot( + index: 0, + selectedId: harness.workspace.id, + unreadCount: 0 + ) + let tab = try #require(snapshot.surfaces.first { + harness.workspace.isRemoteTmuxControlContainer($0.panelId) + }) + let surfaceId = try #require(tab.surfaceId) + + #expect(surfaceId == projectedPanel.id) + #expect(tab.panelId != projectedPanel.id) + guard case .pane = harness.workspace.remoteTmuxControlSurfaceTarget(surfaceID: surfaceId) else { + Issue.record("sidebar surfaceId must resolve to a projected tmux pane") + return + } + } +} + private typealias Harness = RemoteTmuxSessionMirrorLayoutHarness @MainActor