Skip to content

Commit c67dc5a

Browse files
committed
in live modes only push undo stops before first and after last edits, not on each edit
1 parent c4ef9df commit c67dc5a

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/vs/workbench/contrib/interactiveEditor/browser/interactiveEditorStrategies.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ export class LiveStrategy extends EditModeStrategy {
206206
private readonly _inlineDiffDecorations: InlineDiffDecorations;
207207
private readonly _ctxInlineDiff: IContextKey<boolean>;
208208
private _lastResponse?: EditResponse;
209+
private _editCount: number = 0;
209210

210211
constructor(
211212
protected readonly _session: Session,
@@ -255,6 +256,9 @@ export class LiveStrategy extends EditModeStrategy {
255256
}
256257

257258
async apply() {
259+
if (this._editCount > 0) {
260+
this._editor.pushUndoStop();
261+
}
258262
if (this._lastResponse?.workspaceEdits) {
259263
await this._bulkEditService.apply(this._lastResponse.workspaceEdits);
260264
}
@@ -281,7 +285,7 @@ export class LiveStrategy extends EditModeStrategy {
281285
}
282286
}
283287

284-
override async makeChanges(_response: EditResponse, edits: ISingleEditOperation[]): Promise<void> {
288+
override async makeChanges(_response: EditResponse, edits: ISingleEditOperation[], ignoreInlineDiff?: boolean): Promise<void> {
285289
const cursorStateComputerAndInlineDiffCollection: ICursorStateComputer = (undoEdits) => {
286290
let last: Position | null = null;
287291
for (const edit of undoEdits) {
@@ -291,9 +295,11 @@ export class LiveStrategy extends EditModeStrategy {
291295
return last && [Selection.fromPositions(last)];
292296
};
293297

294-
this._editor.pushUndoStop();
295-
this._editor.executeEdits('interactive-editor-live', edits, cursorStateComputerAndInlineDiffCollection);
296-
this._editor.pushUndoStop();
298+
// push undo stop before first edit
299+
if (++this._editCount === 1) {
300+
this._editor.pushUndoStop();
301+
}
302+
this._editor.executeEdits('interactive-editor-live', edits, ignoreInlineDiff ? undefined : cursorStateComputerAndInlineDiffCollection);
297303
}
298304

299305
override async renderChanges(response: EditResponse, textModel0Changes: LineRangeMapping[]) {
@@ -362,9 +368,7 @@ export class LivePreviewStrategy extends LiveStrategy {
362368
}
363369

364370
override async makeChanges(_response: EditResponse, edits: ISingleEditOperation[]): Promise<void> {
365-
this._editor.pushUndoStop();
366-
this._editor.executeEdits('interactive-editor-livePreview', edits);
367-
this._editor.pushUndoStop();
371+
super.makeChanges(_response, edits, true);
368372
}
369373

370374
override async renderChanges(response: EditResponse, changes: LineRangeMapping[]) {

0 commit comments

Comments
 (0)