diff --git a/src/vs/workbench/contrib/chat/browser/widgetHosts/editor/chatEditor.ts b/src/vs/workbench/contrib/chat/browser/widgetHosts/editor/chatEditor.ts index 0a3344392bc4f..688c8c6beec6b 100644 --- a/src/vs/workbench/contrib/chat/browser/widgetHosts/editor/chatEditor.ts +++ b/src/vs/workbench/contrib/chat/browser/widgetHosts/editor/chatEditor.ts @@ -130,6 +130,14 @@ export class ChatEditor extends AbstractEditorWithViewState { this.group.pinEditor(this.input); })); + this._register(this.widget.onDidChangeViewModel((e) => { + if (e.currentSessionResource && this.input instanceof ChatEditorInput) { + const newModel = this.chatService.getSession(e.currentSessionResource); + if (newModel) { + this.input.updateModel(newModel); + } + } + })); this.widget.render(parent); this.widget.setVisible(true); } diff --git a/src/vs/workbench/contrib/chat/browser/widgetHosts/editor/chatEditorInput.ts b/src/vs/workbench/contrib/chat/browser/widgetHosts/editor/chatEditorInput.ts index aa7c5f22a7eed..167dfea479583 100644 --- a/src/vs/workbench/contrib/chat/browser/widgetHosts/editor/chatEditorInput.ts +++ b/src/vs/workbench/contrib/chat/browser/widgetHosts/editor/chatEditorInput.ts @@ -46,6 +46,7 @@ export class ChatEditorInput extends EditorInput implements IEditorCloseHandler private cachedIcon: ThemeIcon | URI | undefined; private readonly modelRef = this._register(new MutableDisposable()); + private readonly _modelChangeListener = this._register(new MutableDisposable()); private get model(): IChatModel | undefined { return this.modelRef.value?.object; @@ -231,11 +232,7 @@ export class ChatEditorInput extends EditorInput implements IEditorCloseHandler this._sessionResource = this.model.sessionResource; - this._register(this.model.onDidChange((e) => { - // Invalidate icon cache when label changes - this.cachedIcon = undefined; - this._onDidChangeLabel.fire(); - })); + this._trackModelChanges(); // Check if icon has changed after model resolution const newIcon = this.resolveIcon(); @@ -248,6 +245,28 @@ export class ChatEditorInput extends EditorInput implements IEditorCloseHandler return this._register(new ChatEditorModel(this.model)); } + /** + * Updates the editor input to track a new model. Called when the widget swaps + * from an untitled session to a real session. + */ + updateModel(model: IChatModel): void { + this._sessionResource = model.sessionResource; + this.modelRef.value = this.chatService.acquireExistingSession(model.sessionResource, 'ChatEditorInput#updateModel'); + this._trackModelChanges(); + this.cachedIcon = undefined; + this._onDidChangeLabel.fire(); + } + + private _trackModelChanges(): void { + if (!this.model) { + return; + } + this._modelChangeListener.value = this.model.onDidChange(() => { + this.cachedIcon = undefined; + this._onDidChangeLabel.fire(); + }); + } + private iconsEqual(a: ThemeIcon | URI, b: ThemeIcon | URI): boolean { if (ThemeIcon.isThemeIcon(a) && ThemeIcon.isThemeIcon(b)) { return a.id === b.id; 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 c9084f2e42353..a3bb64cffb8a6 100644 --- a/src/vs/workbench/contrib/chat/browser/widgetHosts/viewPane/chatViewPane.ts +++ b/src/vs/workbench/contrib/chat/browser/widgetHosts/viewPane/chatViewPane.ts @@ -597,6 +597,9 @@ export class ChatViewPane extends ViewPane implements IViewWelcomeDelegate { // Track the active chat model and reveal it in the sessions control if side-by-side this._register(chatWidget.onDidChangeViewModel(() => { + const model = chatWidget.viewModel?.model; + this.titleControl?.update(model); + if (this.sessionsViewerOrientation === AgentSessionsViewerOrientation.Stacked) { return; // only reveal in side-by-side mode }