Skip to content

Commit 94f9359

Browse files
committed
don't push undo stops for format on save, microsoft#90100
1 parent 09ed1c7 commit 94f9359

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/vs/editor/contrib/format/format.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,8 @@ export async function formatDocumentRangeWithProvider(
178178

179179
if (isCodeEditor(editorOrModel)) {
180180
// use editor to apply edits
181-
FormattingEdit.execute(editorOrModel, edits);
181+
FormattingEdit.execute(editorOrModel, edits, true);
182182
alertFormattingEdits(edits);
183-
editorOrModel.pushUndoStop();
184183
editorOrModel.revealPositionInCenterIfOutsideViewport(editorOrModel.getPosition(), ScrollType.Immediate);
185184

186185
} else {
@@ -265,11 +264,10 @@ export async function formatDocumentWithProvider(
265264

266265
if (isCodeEditor(editorOrModel)) {
267266
// use editor to apply edits
268-
FormattingEdit.execute(editorOrModel, edits);
267+
FormattingEdit.execute(editorOrModel, edits, mode !== FormattingMode.Silent);
269268

270269
if (mode !== FormattingMode.Silent) {
271270
alertFormattingEdits(edits);
272-
editorOrModel.pushUndoStop();
273271
editorOrModel.revealPositionInCenterIfOutsideViewport(editorOrModel.getPosition(), ScrollType.Immediate);
274272
}
275273

src/vs/editor/contrib/format/formattingEdit.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,19 @@ export class FormattingEdit {
4343
return fullModelRange.equalsRange(editRange);
4444
}
4545

46-
static execute(editor: ICodeEditor, _edits: TextEdit[]) {
47-
editor.pushUndoStop();
46+
static execute(editor: ICodeEditor, _edits: TextEdit[], addUndoStops: boolean) {
47+
if (addUndoStops) {
48+
editor.pushUndoStop();
49+
}
4850
const edits = FormattingEdit._handleEolEdits(editor, _edits);
4951
if (edits.length === 1 && FormattingEdit._isFullModelReplaceEdit(editor, edits[0])) {
5052
// We use replace semantics and hope that markers stay put...
5153
editor.executeEdits('formatEditsCommand', edits.map(edit => EditOperation.replace(Range.lift(edit.range), edit.text)));
5254
} else {
5355
editor.executeEdits('formatEditsCommand', edits.map(edit => EditOperation.replaceMove(Range.lift(edit.range), edit.text)));
5456
}
55-
editor.pushUndoStop();
57+
if (addUndoStops) {
58+
editor.pushUndoStop();
59+
}
5660
}
5761
}

src/vs/workbench/api/browser/mainThreadSaveParticipant.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ import { ExtHostContext, ExtHostDocumentSaveParticipantShape, IExtHostContext }
3333
import { ILabelService } from 'vs/platform/label/common/label';
3434
import { canceled } from 'vs/base/common/errors';
3535

36-
export interface ICodeActionsOnSaveOptions {
37-
[kind: string]: boolean;
38-
}
39-
4036
export interface ISaveParticipantParticipant {
4137
participate(model: IResolvedTextFileEditorModel, env: { reason: SaveReason }, progress: IProgress<IProgressStep>, token: CancellationToken): Promise<void>;
4238
}
@@ -242,11 +238,10 @@ class CodeActionOnSaveParticipant implements ISaveParticipantParticipant {
242238
if (env.reason === SaveReason.AUTO) {
243239
return undefined;
244240
}
245-
246241
const model = editorModel.textEditorModel;
247242

248243
const settingsOverrides = { overrideIdentifier: model.getLanguageIdentifier().language, resource: editorModel.resource };
249-
const setting = this._configurationService.getValue<ICodeActionsOnSaveOptions>('editor.codeActionsOnSave', settingsOverrides);
244+
const setting = this._configurationService.getValue<{ [kind: string]: boolean }>('editor.codeActionsOnSave', settingsOverrides);
250245
if (!setting) {
251246
return undefined;
252247
}
@@ -380,9 +375,10 @@ export class SaveParticipant implements ISaveParticipant {
380375
cancellable: true,
381376
delay: model.isDirty() ? 3000 : 5000
382377
}, async progress => {
378+
// undoStop before participation
379+
model.textEditorModel.pushStackElement();
383380

384381
for (let p of this._saveParticipants.getValue()) {
385-
386382
if (cts.token.isCancellationRequested) {
387383
break;
388384
}
@@ -394,6 +390,8 @@ export class SaveParticipant implements ISaveParticipant {
394390
}
395391
}
396392

393+
// undoStop after participation
394+
model.textEditorModel.pushStackElement();
397395
}, () => {
398396
// user cancel
399397
cts.dispose(true);

0 commit comments

Comments
 (0)