提交 e0c24908 编写于 作者: J Johannes Rieken

fix #17246

上级 ef8fdc29
...@@ -18,7 +18,7 @@ import 'vs/editor/contrib/comment/common/comment'; ...@@ -18,7 +18,7 @@ import 'vs/editor/contrib/comment/common/comment';
import 'vs/editor/contrib/contextmenu/browser/contextmenu'; import 'vs/editor/contrib/contextmenu/browser/contextmenu';
import 'vs/editor/contrib/diffNavigator/common/diffNavigator'; import 'vs/editor/contrib/diffNavigator/common/diffNavigator';
import 'vs/editor/contrib/find/browser/find'; import 'vs/editor/contrib/find/browser/find';
import 'vs/editor/contrib/format/common/formatActions'; import 'vs/editor/contrib/format/browser/formatActions';
import 'vs/editor/contrib/goToDeclaration/browser/goToDeclaration'; import 'vs/editor/contrib/goToDeclaration/browser/goToDeclaration';
import 'vs/editor/contrib/gotoError/browser/gotoError'; import 'vs/editor/contrib/gotoError/browser/gotoError';
import 'vs/editor/contrib/hover/browser/hover'; import 'vs/editor/contrib/hover/browser/hover';
......
...@@ -14,16 +14,40 @@ import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; ...@@ -14,16 +14,40 @@ import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { editorAction, ServicesAccessor, EditorAction, commonEditorContribution } from 'vs/editor/common/editorCommonExtensions'; import { editorAction, ServicesAccessor, EditorAction, commonEditorContribution } from 'vs/editor/common/editorCommonExtensions';
import { OnTypeFormattingEditProviderRegistry, DocumentRangeFormattingEditProviderRegistry } from 'vs/editor/common/modes'; import { OnTypeFormattingEditProviderRegistry, DocumentRangeFormattingEditProviderRegistry } from 'vs/editor/common/modes';
import { getOnTypeFormattingEdits, getDocumentFormattingEdits, getDocumentRangeFormattingEdits } from '../common/format'; import { getOnTypeFormattingEdits, getDocumentFormattingEdits, getDocumentRangeFormattingEdits } from '../common/format';
import { EditOperationsCommand } from './formatCommand'; import { EditOperationsCommand } from '../common/formatCommand';
import { CommandsRegistry } from 'vs/platform/commands/common/commands'; import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { ICodeEditorService } from 'vs/editor/common/services/codeEditorService'; import { ICodeEditorService } from 'vs/editor/common/services/codeEditorService';
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService'; import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService';
import { CharacterSet } from 'vs/editor/common/core/characterClassifier'; import { CharacterSet } from 'vs/editor/common/core/characterClassifier';
import { Range } from 'vs/editor/common/core/range'; import { Range } from 'vs/editor/common/core/range';
import { alert } from 'vs/base/browser/ui/aria/aria';
import ModeContextKeys = editorCommon.ModeContextKeys; import ModeContextKeys = editorCommon.ModeContextKeys;
import EditorContextKeys = editorCommon.EditorContextKeys; import EditorContextKeys = editorCommon.EditorContextKeys;
function alertFormattingEdits(edits: editorCommon.ISingleEditOperation[]): void {
let { range } = edits[0];
for (let i = 1; i < edits.length; i++) {
range = Range.plusRange(range, edits[i].range);
}
const { startLineNumber, endLineNumber } = range;
if (startLineNumber === endLineNumber) {
if (edits.length === 1) {
alert(nls.localize('hint11', "Made 1 formatting edit on line {0}", startLineNumber));
} else {
alert(nls.localize('hintn1', "Made {0} formatting edits on line {1}", edits.length, startLineNumber));
}
} else {
if (edits.length === 1) {
alert(nls.localize('hint1n', "Made 1 formatting edit between lines {0} and {1}", startLineNumber, endLineNumber));
} else {
alert(nls.localize('hintnn', "Made {0} formatting edits between lines {1} and {2}", edits.length, startLineNumber, endLineNumber));
}
}
}
@commonEditorContribution @commonEditorContribution
class FormatOnType implements editorCommon.IEditorContribution { class FormatOnType implements editorCommon.IEditorContribution {
...@@ -134,6 +158,7 @@ class FormatOnType implements editorCommon.IEditorContribution { ...@@ -134,6 +158,7 @@ class FormatOnType implements editorCommon.IEditorContribution {
} }
this.editor.executeCommand(this.getId(), new EditOperationsCommand(edits, this.editor.getSelection())); this.editor.executeCommand(this.getId(), new EditOperationsCommand(edits, this.editor.getSelection()));
alertFormattingEdits(edits);
}, (err) => { }, (err) => {
unbind.dispose(); unbind.dispose();
...@@ -218,6 +243,7 @@ class FormatOnPaste implements editorCommon.IEditorContribution { ...@@ -218,6 +243,7 @@ class FormatOnPaste implements editorCommon.IEditorContribution {
} }
const command = new EditOperationsCommand(edits, this.editor.getSelection()); const command = new EditOperationsCommand(edits, this.editor.getSelection());
this.editor.executeCommand(this.getId(), command); this.editor.executeCommand(this.getId(), command);
alertFormattingEdits(edits);
}); });
} }
...@@ -252,6 +278,7 @@ export abstract class AbstractFormatAction extends EditorAction { ...@@ -252,6 +278,7 @@ export abstract class AbstractFormatAction extends EditorAction {
} }
const command = new EditOperationsCommand(edits, editor.getSelection()); const command = new EditOperationsCommand(edits, editor.getSelection());
editor.executeCommand(this.id, command); editor.executeCommand(this.id, command);
alertFormattingEdits(edits);
editor.focus(); editor.focus();
}); });
} }
...@@ -284,7 +311,7 @@ export class FormatDocumentAction extends AbstractFormatAction { ...@@ -284,7 +311,7 @@ export class FormatDocumentAction extends AbstractFormatAction {
protected _getFormattingEdits(editor: editorCommon.ICommonCodeEditor): TPromise<editorCommon.ISingleEditOperation[]> { protected _getFormattingEdits(editor: editorCommon.ICommonCodeEditor): TPromise<editorCommon.ISingleEditOperation[]> {
const model = editor.getModel(); const model = editor.getModel();
const { tabSize, insertSpaces} = model.getOptions(); const { tabSize, insertSpaces } = model.getOptions();
return getDocumentFormattingEdits(model, { tabSize, insertSpaces }); return getDocumentFormattingEdits(model, { tabSize, insertSpaces });
} }
} }
...@@ -311,7 +338,7 @@ export class FormatSelectionAction extends AbstractFormatAction { ...@@ -311,7 +338,7 @@ export class FormatSelectionAction extends AbstractFormatAction {
protected _getFormattingEdits(editor: editorCommon.ICommonCodeEditor): TPromise<editorCommon.ISingleEditOperation[]> { protected _getFormattingEdits(editor: editorCommon.ICommonCodeEditor): TPromise<editorCommon.ISingleEditOperation[]> {
const model = editor.getModel(); const model = editor.getModel();
const { tabSize, insertSpaces} = model.getOptions(); const { tabSize, insertSpaces } = model.getOptions();
return getDocumentRangeFormattingEdits(model, editor.getSelection(), { tabSize, insertSpaces }); return getDocumentRangeFormattingEdits(model, editor.getSelection(), { tabSize, insertSpaces });
} }
} }
...@@ -328,7 +355,7 @@ CommandsRegistry.registerCommand('editor.action.format', accessor => { ...@@ -328,7 +355,7 @@ CommandsRegistry.registerCommand('editor.action.format', accessor => {
_getFormattingEdits(editor: editorCommon.ICommonCodeEditor): TPromise<editorCommon.ISingleEditOperation[]> { _getFormattingEdits(editor: editorCommon.ICommonCodeEditor): TPromise<editorCommon.ISingleEditOperation[]> {
const model = editor.getModel(); const model = editor.getModel();
const editorSelection = editor.getSelection(); const editorSelection = editor.getSelection();
const {tabSize, insertSpaces } = model.getOptions(); const { tabSize, insertSpaces } = model.getOptions();
return editorSelection.isEmpty() return editorSelection.isEmpty()
? getDocumentFormattingEdits(model, { tabSize, insertSpaces }) ? getDocumentFormattingEdits(model, { tabSize, insertSpaces })
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册