From 94f93598c5f87aa49b58aa46fa80371952b446da Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Thu, 6 Feb 2020 11:35:40 +0100 Subject: [PATCH] don't push undo stops for format on save, #90100 --- src/vs/editor/contrib/format/format.ts | 6 ++---- src/vs/editor/contrib/format/formattingEdit.ts | 10 +++++++--- .../api/browser/mainThreadSaveParticipant.ts | 12 +++++------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/vs/editor/contrib/format/format.ts b/src/vs/editor/contrib/format/format.ts index 8747d4bc17b..84e4007bce6 100644 --- a/src/vs/editor/contrib/format/format.ts +++ b/src/vs/editor/contrib/format/format.ts @@ -178,9 +178,8 @@ export async function formatDocumentRangeWithProvider( if (isCodeEditor(editorOrModel)) { // use editor to apply edits - FormattingEdit.execute(editorOrModel, edits); + FormattingEdit.execute(editorOrModel, edits, true); alertFormattingEdits(edits); - editorOrModel.pushUndoStop(); editorOrModel.revealPositionInCenterIfOutsideViewport(editorOrModel.getPosition(), ScrollType.Immediate); } else { @@ -265,11 +264,10 @@ export async function formatDocumentWithProvider( if (isCodeEditor(editorOrModel)) { // use editor to apply edits - FormattingEdit.execute(editorOrModel, edits); + FormattingEdit.execute(editorOrModel, edits, mode !== FormattingMode.Silent); if (mode !== FormattingMode.Silent) { alertFormattingEdits(edits); - editorOrModel.pushUndoStop(); editorOrModel.revealPositionInCenterIfOutsideViewport(editorOrModel.getPosition(), ScrollType.Immediate); } diff --git a/src/vs/editor/contrib/format/formattingEdit.ts b/src/vs/editor/contrib/format/formattingEdit.ts index 27dbbd06762..cabb0a73d7a 100644 --- a/src/vs/editor/contrib/format/formattingEdit.ts +++ b/src/vs/editor/contrib/format/formattingEdit.ts @@ -43,8 +43,10 @@ export class FormattingEdit { return fullModelRange.equalsRange(editRange); } - static execute(editor: ICodeEditor, _edits: TextEdit[]) { - editor.pushUndoStop(); + static execute(editor: ICodeEditor, _edits: TextEdit[], addUndoStops: boolean) { + if (addUndoStops) { + editor.pushUndoStop(); + } const edits = FormattingEdit._handleEolEdits(editor, _edits); if (edits.length === 1 && FormattingEdit._isFullModelReplaceEdit(editor, edits[0])) { // We use replace semantics and hope that markers stay put... @@ -52,6 +54,8 @@ export class FormattingEdit { } else { editor.executeEdits('formatEditsCommand', edits.map(edit => EditOperation.replaceMove(Range.lift(edit.range), edit.text))); } - editor.pushUndoStop(); + if (addUndoStops) { + editor.pushUndoStop(); + } } } diff --git a/src/vs/workbench/api/browser/mainThreadSaveParticipant.ts b/src/vs/workbench/api/browser/mainThreadSaveParticipant.ts index 11078045683..3cd807c4cce 100644 --- a/src/vs/workbench/api/browser/mainThreadSaveParticipant.ts +++ b/src/vs/workbench/api/browser/mainThreadSaveParticipant.ts @@ -33,10 +33,6 @@ import { ExtHostContext, ExtHostDocumentSaveParticipantShape, IExtHostContext } import { ILabelService } from 'vs/platform/label/common/label'; import { canceled } from 'vs/base/common/errors'; -export interface ICodeActionsOnSaveOptions { - [kind: string]: boolean; -} - export interface ISaveParticipantParticipant { participate(model: IResolvedTextFileEditorModel, env: { reason: SaveReason }, progress: IProgress, token: CancellationToken): Promise; } @@ -242,11 +238,10 @@ class CodeActionOnSaveParticipant implements ISaveParticipantParticipant { if (env.reason === SaveReason.AUTO) { return undefined; } - const model = editorModel.textEditorModel; const settingsOverrides = { overrideIdentifier: model.getLanguageIdentifier().language, resource: editorModel.resource }; - const setting = this._configurationService.getValue('editor.codeActionsOnSave', settingsOverrides); + const setting = this._configurationService.getValue<{ [kind: string]: boolean }>('editor.codeActionsOnSave', settingsOverrides); if (!setting) { return undefined; } @@ -380,9 +375,10 @@ export class SaveParticipant implements ISaveParticipant { cancellable: true, delay: model.isDirty() ? 3000 : 5000 }, async progress => { + // undoStop before participation + model.textEditorModel.pushStackElement(); for (let p of this._saveParticipants.getValue()) { - if (cts.token.isCancellationRequested) { break; } @@ -394,6 +390,8 @@ export class SaveParticipant implements ISaveParticipant { } } + // undoStop after participation + model.textEditorModel.pushStackElement(); }, () => { // user cancel cts.dispose(true); -- GitLab