diff --git a/src/vs/workbench/api/node/mainThreadSaveParticipant.ts b/src/vs/workbench/api/node/mainThreadSaveParticipant.ts index a2b4de39275..72faf6f7b70 100644 --- a/src/vs/workbench/api/node/mainThreadSaveParticipant.ts +++ b/src/vs/workbench/api/node/mainThreadSaveParticipant.ts @@ -86,7 +86,7 @@ class FormatOnSaveParticipant implements ISaveParticipant { participate(editorModel: ITextFileEditorModel, env: { isAutoSaved: boolean }): TPromise { - if (!this._configurationService.lookup('files.formatOnSave').value) { + if (env.isAutoSaved || !this._configurationService.lookup('files.formatOnSave').value) { return; } @@ -97,7 +97,7 @@ class FormatOnSaveParticipant implements ISaveParticipant { return getDocumentRangeFormattingEdits(model, model.getFullModelRange(), { tabSize, insertSpaces }).then(edits => { if (edits) { if (editor) { - this._editsWithEditor(editor, edits, env.isAutoSaved); + this._editsWithEditor(editor, edits); } else { this._editWithModel(model, edits); } @@ -105,27 +105,7 @@ class FormatOnSaveParticipant implements ISaveParticipant { }); } - private _editsWithEditor(editor: ICommonCodeEditor, edits: ISingleEditOperation[], isAutoSaved: boolean): void { - - if (isAutoSaved && editor.isFocused()) { - // when we save an focus (active) editor we check if - // formatting edits intersect with any cursor. iff so - // we ignore this - - let intersectsCursor = false; - outer: for (const selection of editor.getSelections()) { - for (const {range} of edits) { - if (Range.areIntersectingOrTouching(range, selection)) { - intersectsCursor = true; - break outer; - } - } - } - if (intersectsCursor) { - return; - } - } - + private _editsWithEditor(editor: ICommonCodeEditor, edits: ISingleEditOperation[]): void { editor.executeCommand('files.formatOnSave', new EditOperationsCommand(edits, editor.getSelection())); } diff --git a/src/vs/workbench/parts/files/browser/files.contribution.ts b/src/vs/workbench/parts/files/browser/files.contribution.ts index d9a1355dafe..3c0f238d3b5 100644 --- a/src/vs/workbench/parts/files/browser/files.contribution.ts +++ b/src/vs/workbench/parts/files/browser/files.contribution.ts @@ -215,7 +215,7 @@ configurationRegistry.registerConfiguration({ 'files.formatOnSave': { 'type': 'boolean', 'default': false, - 'description': nls.localize('formatOnSave', "Format a file on save - a matching formatting provider must be available.") + 'description': nls.localize('formatOnSave', "Format a file on save. A formatter must be available and the file must not be auto-saved") }, 'files.autoSave': { 'type': 'string',