Skip to content

Commit 0021ada

Browse files
authored
fix: restore chat attachments when cycling through chat input history (microsoft#223782)
* fix: save chat attachments for chat history before clearing them * fix: avoid firing change event if no attachments were removed * fix: don't clear existing attachments when appending new ones
1 parent 2bd00c0 commit 0021ada

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/vs/workbench/contrib/chat/browser/chatInputPart.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,18 +348,20 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
348348
}
349349

350350
attachContext(overwrite: boolean, ...contentReferences: IChatRequestVariableEntry[]): void {
351-
const removed = Array.from(this._attachedContext);
351+
const removed = [];
352352
if (overwrite) {
353+
removed.push(...Array.from(this._attachedContext));
353354
this._attachedContext.clear();
354355
}
355356

356357
if (contentReferences.length > 0) {
357358
for (const reference of contentReferences) {
358359
this._attachedContext.add(reference);
359360
}
360-
this.initAttachedContext(this.attachedContextContainer);
361361
}
362+
362363
if (removed.length > 0 || contentReferences.length > 0) {
364+
this.initAttachedContext(this.attachedContextContainer);
363365
this._onDidChangeContext.fire({ removed, added: contentReferences });
364366
}
365367
}

src/vs/workbench/contrib/chat/browser/chatWidget.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,10 +786,10 @@ export class ChatWidget extends Disposable implements IChatWidget {
786786
});
787787

788788
if (result) {
789-
this.inputPart.clearContext();
790789
this.inputPart.acceptInput(isUserQuery);
791790
this._onDidSubmitAgent.fire({ agent: result.agent, slashCommand: result.slashCommand });
792791
this.inputPart.updateState(this.collectInputState());
792+
this.inputPart.clearContext();
793793
result.responseCompletePromise.then(() => {
794794
const responses = this.viewModel?.getItems().filter(isResponseVM);
795795
const lastResponse = responses?.[responses.length - 1];

src/vs/workbench/contrib/chat/browser/contrib/chatContextAttachments.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ export class ChatContextAttachments extends Disposable implements IChatWidgetCon
7070
}
7171

7272
private _removeContext(attachments: IChatRequestVariableEntry[]) {
73-
attachments.forEach(this._attachedContext.delete, this._attachedContext);
74-
this._onDidChangeInputState.fire();
73+
if (attachments.length) {
74+
attachments.forEach(this._attachedContext.delete, this._attachedContext);
75+
this._onDidChangeInputState.fire();
76+
}
7577
}
7678

7779
private _clearAttachedContext() {

0 commit comments

Comments
 (0)