diff --git a/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessions.ts b/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessions.ts index 474f1a2530a..e9e4553e093 100644 --- a/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessions.ts +++ b/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessions.ts @@ -117,7 +117,11 @@ export interface IAgentSessionsControl { refresh(): void; openFind(): void; - reveal(sessionResource: URI): void; + + reveal(sessionResource: URI): boolean; + + clearFocus(): void; + hasFocusOrSelection(): boolean; } export const agentSessionReadIndicatorForeground = registerColor( diff --git a/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsControl.ts b/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsControl.ts index 94653334478..0e6ae13f0ed 100644 --- a/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsControl.ts +++ b/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsControl.ts @@ -371,6 +371,10 @@ export class AgentSessionsControl extends Disposable implements IAgentSessionsCo this.sessionsList?.setSelection([]); } + hasFocusOrSelection(): boolean { + return (this.sessionsList?.getFocus().length ?? 0) > 0 || (this.sessionsList?.getSelection().length ?? 0) > 0; + } + scrollToTop(): void { if (this.sessionsList) { this.sessionsList.scrollTop = 0; @@ -383,14 +387,14 @@ export class AgentSessionsControl extends Disposable implements IAgentSessionsCo return focused.filter(e => isAgentSession(e)); } - reveal(sessionResource: URI): void { + reveal(sessionResource: URI): boolean { if (!this.sessionsList) { - return; + return false; } const session = this.agentSessionsService.model.getSession(sessionResource); if (!session || !this.sessionsList.hasNode(session)) { - return; + return false; } if (this.sessionsList.getRelativeTop(session) === null) { @@ -399,5 +403,7 @@ export class AgentSessionsControl extends Disposable implements IAgentSessionsCo this.sessionsList.setFocus([session]); this.sessionsList.setSelection([session]); + + return true; } } diff --git a/src/vs/workbench/contrib/chat/browser/widgetHosts/viewPane/chatViewPane.ts b/src/vs/workbench/contrib/chat/browser/widgetHosts/viewPane/chatViewPane.ts index a520cc59bdc..903feab80e2 100644 --- a/src/vs/workbench/contrib/chat/browser/widgetHosts/viewPane/chatViewPane.ts +++ b/src/vs/workbench/contrib/chat/browser/widgetHosts/viewPane/chatViewPane.ts @@ -594,6 +594,28 @@ export class ChatViewPane extends ViewPane implements IViewWelcomeDelegate { return; // only reveal in side-by-side mode } + const sessionResource = chatWidget.viewModel?.sessionResource; + if (sessionResource) { + const revealed = sessionsControl.reveal(sessionResource); + if (!revealed) { + // Session doesn't exist in the list yet (e.g., new untitled session), + // clear the selection so the list doesn't show stale selection + sessionsControl.clearFocus(); + } + } + })); + + // When sessions change (e.g., after first message in a new session) + // reveal it unless the user is interacting with the list already + this._register(this.agentSessionsService.model.onDidChangeSessions(() => { + if (this.sessionsViewerOrientation === AgentSessionsViewerOrientation.Stacked) { + return; // only reveal in side-by-side mode + } + + if (sessionsControl.hasFocusOrSelection()) { + return; // do not reveal if user is interacting with sessions control + } + const sessionResource = chatWidget.viewModel?.sessionResource; if (sessionResource) { sessionsControl.reveal(sessionResource);