提交 94f93598 编写于 作者: J Johannes Rieken

don't push undo stops for format on save, #90100

上级 09ed1c7c
...@@ -178,9 +178,8 @@ export async function formatDocumentRangeWithProvider( ...@@ -178,9 +178,8 @@ export async function formatDocumentRangeWithProvider(
if (isCodeEditor(editorOrModel)) { if (isCodeEditor(editorOrModel)) {
// use editor to apply edits // use editor to apply edits
FormattingEdit.execute(editorOrModel, edits); FormattingEdit.execute(editorOrModel, edits, true);
alertFormattingEdits(edits); alertFormattingEdits(edits);
editorOrModel.pushUndoStop();
editorOrModel.revealPositionInCenterIfOutsideViewport(editorOrModel.getPosition(), ScrollType.Immediate); editorOrModel.revealPositionInCenterIfOutsideViewport(editorOrModel.getPosition(), ScrollType.Immediate);
} else { } else {
...@@ -265,11 +264,10 @@ export async function formatDocumentWithProvider( ...@@ -265,11 +264,10 @@ export async function formatDocumentWithProvider(
if (isCodeEditor(editorOrModel)) { if (isCodeEditor(editorOrModel)) {
// use editor to apply edits // use editor to apply edits
FormattingEdit.execute(editorOrModel, edits); FormattingEdit.execute(editorOrModel, edits, mode !== FormattingMode.Silent);
if (mode !== FormattingMode.Silent) { if (mode !== FormattingMode.Silent) {
alertFormattingEdits(edits); alertFormattingEdits(edits);
editorOrModel.pushUndoStop();
editorOrModel.revealPositionInCenterIfOutsideViewport(editorOrModel.getPosition(), ScrollType.Immediate); editorOrModel.revealPositionInCenterIfOutsideViewport(editorOrModel.getPosition(), ScrollType.Immediate);
} }
......
...@@ -43,8 +43,10 @@ export class FormattingEdit { ...@@ -43,8 +43,10 @@ export class FormattingEdit {
return fullModelRange.equalsRange(editRange); return fullModelRange.equalsRange(editRange);
} }
static execute(editor: ICodeEditor, _edits: TextEdit[]) { static execute(editor: ICodeEditor, _edits: TextEdit[], addUndoStops: boolean) {
editor.pushUndoStop(); if (addUndoStops) {
editor.pushUndoStop();
}
const edits = FormattingEdit._handleEolEdits(editor, _edits); const edits = FormattingEdit._handleEolEdits(editor, _edits);
if (edits.length === 1 && FormattingEdit._isFullModelReplaceEdit(editor, edits[0])) { if (edits.length === 1 && FormattingEdit._isFullModelReplaceEdit(editor, edits[0])) {
// We use replace semantics and hope that markers stay put... // We use replace semantics and hope that markers stay put...
...@@ -52,6 +54,8 @@ export class FormattingEdit { ...@@ -52,6 +54,8 @@ export class FormattingEdit {
} else { } else {
editor.executeEdits('formatEditsCommand', edits.map(edit => EditOperation.replaceMove(Range.lift(edit.range), edit.text))); editor.executeEdits('formatEditsCommand', edits.map(edit => EditOperation.replaceMove(Range.lift(edit.range), edit.text)));
} }
editor.pushUndoStop(); if (addUndoStops) {
editor.pushUndoStop();
}
} }
} }
...@@ -33,10 +33,6 @@ import { ExtHostContext, ExtHostDocumentSaveParticipantShape, IExtHostContext } ...@@ -33,10 +33,6 @@ import { ExtHostContext, ExtHostDocumentSaveParticipantShape, IExtHostContext }
import { ILabelService } from 'vs/platform/label/common/label'; import { ILabelService } from 'vs/platform/label/common/label';
import { canceled } from 'vs/base/common/errors'; import { canceled } from 'vs/base/common/errors';
export interface ICodeActionsOnSaveOptions {
[kind: string]: boolean;
}
export interface ISaveParticipantParticipant { export interface ISaveParticipantParticipant {
participate(model: IResolvedTextFileEditorModel, env: { reason: SaveReason }, progress: IProgress<IProgressStep>, token: CancellationToken): Promise<void>; participate(model: IResolvedTextFileEditorModel, env: { reason: SaveReason }, progress: IProgress<IProgressStep>, token: CancellationToken): Promise<void>;
} }
...@@ -242,11 +238,10 @@ class CodeActionOnSaveParticipant implements ISaveParticipantParticipant { ...@@ -242,11 +238,10 @@ class CodeActionOnSaveParticipant implements ISaveParticipantParticipant {
if (env.reason === SaveReason.AUTO) { if (env.reason === SaveReason.AUTO) {
return undefined; return undefined;
} }
const model = editorModel.textEditorModel; const model = editorModel.textEditorModel;
const settingsOverrides = { overrideIdentifier: model.getLanguageIdentifier().language, resource: editorModel.resource }; const settingsOverrides = { overrideIdentifier: model.getLanguageIdentifier().language, resource: editorModel.resource };
const setting = this._configurationService.getValue<ICodeActionsOnSaveOptions>('editor.codeActionsOnSave', settingsOverrides); const setting = this._configurationService.getValue<{ [kind: string]: boolean }>('editor.codeActionsOnSave', settingsOverrides);
if (!setting) { if (!setting) {
return undefined; return undefined;
} }
...@@ -380,9 +375,10 @@ export class SaveParticipant implements ISaveParticipant { ...@@ -380,9 +375,10 @@ export class SaveParticipant implements ISaveParticipant {
cancellable: true, cancellable: true,
delay: model.isDirty() ? 3000 : 5000 delay: model.isDirty() ? 3000 : 5000
}, async progress => { }, async progress => {
// undoStop before participation
model.textEditorModel.pushStackElement();
for (let p of this._saveParticipants.getValue()) { for (let p of this._saveParticipants.getValue()) {
if (cts.token.isCancellationRequested) { if (cts.token.isCancellationRequested) {
break; break;
} }
...@@ -394,6 +390,8 @@ export class SaveParticipant implements ISaveParticipant { ...@@ -394,6 +390,8 @@ export class SaveParticipant implements ISaveParticipant {
} }
} }
// undoStop after participation
model.textEditorModel.pushStackElement();
}, () => { }, () => {
// user cancel // user cancel
cts.dispose(true); cts.dispose(true);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册