From 1709b5eb569626abd6f7136894de81efa2b1c562 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Sun, 25 Jan 2026 16:03:39 +0000 Subject: [PATCH] Fix session list selection when adding new session in side-by-side view (#290233) * Initial plan * Fix session list selection when adding new session in side-by-side view - Clear list selection when creating a new untitled session - Reveal session in list after first message is submitted - Change reveal() return type from void to boolean - Add onDidChangeSessions listener to auto-select session when it appears Co-authored-by: bpasero <900690+bpasero@users.noreply.github.com> * Add comment explaining why reveal() return value is ignored in onDidChangeSessions Co-authored-by: bpasero <900690+bpasero@users.noreply.github.com> * . * . --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bpasero <900690+bpasero@users.noreply.github.com> Co-authored-by: Benjamin Pasero --- .../browser/agentSessions/agentSessions.ts | 6 ++++- .../agentSessions/agentSessionsControl.ts | 12 +++++++--- .../widgetHosts/viewPane/chatViewPane.ts | 22 +++++++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) 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);