Skip to content

Commit

Permalink
Single render for multiple file removal from working set (microsoft#2…
Browse files Browse the repository at this point in the history
…34684)

only render once when removing many files from working set
  • Loading branch information
benibenj authored Nov 27, 2024
1 parent f68cdda commit 1c23e6f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
18 changes: 11 additions & 7 deletions src/vs/workbench/contrib/chat/browser/chatAttachmentModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ export class ChatAttachmentModel extends Disposable {
this._onDidChangeContext.fire();
}

delete(variableEntryId: string) {
this._attachments.delete(variableEntryId);
delete(...variableEntryIds: string[]) {
for (const variableEntryId of variableEntryIds) {
this._attachments.delete(variableEntryId);
}
this._onDidChangeContext.fire();
}

Expand Down Expand Up @@ -122,13 +124,15 @@ export class EditsAttachmentModel extends ChatAttachmentModel {
super.clear();
}

override delete(variableEntryId: string) {
const excludedFileIndex = this._excludedFileAttachments.findIndex(attachment => attachment.id === variableEntryId);
if (excludedFileIndex !== -1) {
this._excludedFileAttachments.splice(excludedFileIndex, 1);
override delete(...variableEntryIds: string[]) {
for (const variableEntryId of variableEntryIds) {
const excludedFileIndex = this._excludedFileAttachments.findIndex(attachment => attachment.id === variableEntryId);
if (excludedFileIndex !== -1) {
this._excludedFileAttachments.splice(excludedFileIndex, 1);
}
}

super.delete(variableEntryId);
super.delete(...variableEntryIds);

if (this.fileAttachments.length < this._chatEditingService.editingSessionFileLimit) {
const availableFileCount = Math.max(0, this._chatEditingService.editingSessionFileLimit - this.fileAttachments.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,9 @@ export class ChatEditingRemoveAllFilesAction extends Action2 {
// Remove all file attachments
const attachmentModel = chatWidget?.attachmentModel as EditsAttachmentModel | undefined;
const fileAttachments = attachmentModel ? [...attachmentModel.excludedFileAttachments, ...attachmentModel.fileAttachments] : [];
for (const uri of fileAttachments) {
if (URI.isUri(uri.value)) {
chatWidget?.attachmentModel.delete(uri.value.toString());
}
}

const attachmentIdsToRemove = fileAttachments.map(attachment => (attachment.value as URI).toString());
chatWidget?.attachmentModel.delete(...attachmentIdsToRemove);
}
}
registerAction2(ChatEditingRemoveAllFilesAction);
Expand Down

0 comments on commit 1c23e6f

Please sign in to comment.