Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ export class ChatEditor extends AbstractEditorWithViewState<IChatEditorViewState
this._register(this.widget.onDidSubmitAgent(() => {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class ChatEditorInput extends EditorInput implements IEditorCloseHandler
private cachedIcon: ThemeIcon | URI | undefined;

private readonly modelRef = this._register(new MutableDisposable<IChatModelReference>());
private readonly _modelChangeListener = this._register(new MutableDisposable());

private get model(): IChatModel | undefined {
return this.modelRef.value?.object;
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Comment thread
mjbvz marked this conversation as resolved.
}

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading