Skip to content

Commit 462abd6

Browse files
authored
Re-render the actions on each update and reset an entry's state if it is edited (microsoft#229840)
1 parent d4a6f20 commit 462abd6

File tree

2 files changed

+49
-37
lines changed

2 files changed

+49
-37
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ class ChatEditingSession extends Disposable implements IChatEditingSession {
727727

728728
private async _acceptTextEdits(resource: URI, textEdits: TextEdit[]): Promise<void> {
729729
const entry = await this._getOrCreateModifiedFileEntry(resource);
730-
entry.doc.applyEdits(textEdits);
730+
entry.appyEdits(textEdits);
731731
}
732732

733733
private async _resolve(): Promise<void> {
@@ -779,7 +779,7 @@ class ModifiedFileEntry extends Disposable implements IModifiedFileEntry {
779779
public readonly entryId = `${ModifiedFileEntry.scheme}::${++ModifiedFileEntry.lastEntryId}`;
780780

781781
public readonly docSnapshot: ITextModel;
782-
public readonly doc: ITextModel;
782+
private readonly doc: ITextModel;
783783

784784
get originalURI(): URI {
785785
return this.docSnapshot.uri;
@@ -815,6 +815,11 @@ class ModifiedFileEntry extends Disposable implements IModifiedFileEntry {
815815
this._register(resourceRef);
816816
}
817817

818+
appyEdits(textEdits: TextEdit[]): void {
819+
this.doc.applyEdits(textEdits);
820+
this._stateObs.set(ModifiedFileEntryState.Undecided, undefined);
821+
}
822+
818823
async accept(transaction: ITransaction | undefined): Promise<void> {
819824
if (this._stateObs.get() !== ModifiedFileEntryState.Undecided) {
820825
// already accepted or rejected

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

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
200200

201201
readonly inputUri = URI.parse(`${ChatInputPart.INPUT_SCHEME}:input-${ChatInputPart._counter++}`);
202202

203+
private readonly _chatEditsActionsDisposables = this._register(new DisposableStore());
203204
private readonly _chatEditsDisposables = this._register(new DisposableStore());
204205
private _chatEditsProgress: ProgressBar | undefined;
205206
private _chatEditsListPool: CollapsibleListPool;
@@ -866,49 +867,55 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
866867
: localize('chatEditingSessionOverview', "{0} files changed", numberOfEditedEntries);
867868
}
868869

869-
// Chat editing session actions
870-
let actionsContainer = overviewRegion.querySelector('.chat-editing-session-actions') as HTMLElement;
871-
const actions = [];
872-
if (!actionsContainer && chatEditingSession.entries.get().find((e) => e.state.get() === ModifiedFileEntryState.Undecided)) {
873-
// Don't show Accept All / Discard All actions if user already selected Accept All / Discard All
874-
actionsContainer = dom.append(overviewRegion, $('.chat-editing-session-actions'));
875-
actions.push(
876-
{
877-
command: ChatEditingShowChangesAction.ID,
878-
label: ChatEditingShowChangesAction.LABEL,
879-
isSecondary: true
880-
},
881-
{
882-
command: ChatEditingDiscardAllAction.ID,
883-
label: ChatEditingDiscardAllAction.LABEL,
884-
isSecondary: true
885-
},
886-
{
887-
command: ChatEditingAcceptAllAction.ID,
888-
label: ChatEditingAcceptAllAction.LABEL,
889-
isSecondary: false
870+
//#region Chat editing session actions
871+
{
872+
const actionsContainer = overviewRegion.querySelector('.chat-editing-session-actions') as HTMLElement ?? dom.append(overviewRegion, $('.chat-editing-session-actions'));
873+
// Clear out the previous actions (if any)
874+
this._chatEditsActionsDisposables.clear();
875+
dom.clearNode(actionsContainer);
876+
877+
if (chatEditingSession.entries.get().find((e) => e.state.get() === ModifiedFileEntryState.Undecided)) {
878+
// Don't show Accept All / Discard All actions if user already selected Accept All / Discard All
879+
const actions = [];
880+
actions.push(
881+
{
882+
command: ChatEditingShowChangesAction.ID,
883+
label: ChatEditingShowChangesAction.LABEL,
884+
isSecondary: true
885+
},
886+
{
887+
command: ChatEditingDiscardAllAction.ID,
888+
label: ChatEditingDiscardAllAction.LABEL,
889+
isSecondary: true
890+
},
891+
{
892+
command: ChatEditingAcceptAllAction.ID,
893+
label: ChatEditingAcceptAllAction.LABEL,
894+
isSecondary: false
895+
}
896+
);
897+
898+
for (const action of actions) {
899+
const button = this._chatEditsActionsDisposables.add(new Button(actionsContainer, {
900+
supportIcons: false,
901+
secondary: action.isSecondary
902+
}));
903+
button.label = action.label;
904+
this._chatEditsActionsDisposables.add(button.onDidClick(() => {
905+
this.commandService.executeCommand(action.command);
906+
}));
907+
dom.append(actionsContainer, button.element);
890908
}
891-
);
892-
893-
for (const action of actions) {
894-
const button = this._chatEditsDisposables.add(new Button(actionsContainer, {
895-
supportIcons: false,
896-
secondary: action.isSecondary
897-
}));
898-
button.label = action.label;
899-
this._chatEditsDisposables.add(button.onDidClick(() => {
900-
this.commandService.executeCommand(action.command);
901-
}));
902-
dom.append(actionsContainer, button.element);
903909
}
904910

905-
const clearButton = this._chatEditsDisposables.add(new Button(actionsContainer, { supportIcons: true }));
911+
const clearButton = this._chatEditsActionsDisposables.add(new Button(actionsContainer, { supportIcons: true }));
906912
clearButton.icon = Codicon.close;
907-
this._chatEditsDisposables.add(clearButton.onDidClick((e) => {
913+
this._chatEditsActionsDisposables.add(clearButton.onDidClick((e) => {
908914
void chatEditingSession.stop();
909915
}));
910916
dom.append(actionsContainer, clearButton.element);
911917
}
918+
//#endregion
912919

913920
if (!this._chatEditsProgress && chatEditingSession.state.get() === ChatEditingSessionState.StreamingEdits) {
914921
this._chatEditsProgress = new ProgressBar(innerContainer);

0 commit comments

Comments
 (0)