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 <benjamin.pasero@microsoft.com>
This commit is contained in:
Copilot
2026-01-25 16:03:39 +00:00
committed by GitHub
parent 390f10d3c1
commit 1709b5eb56
3 changed files with 36 additions and 4 deletions

View File

@@ -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(

View File

@@ -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;
}
}

View File

@@ -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);