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

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

上级 09ed1c7c
......@@ -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);
}
......
......@@ -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();
}
}
}
......@@ -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<IProgressStep>, token: CancellationToken): Promise<void>;
}
......@@ -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<ICodeActionsOnSaveOptions>('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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册