Remove optional argument, document reason for looking at args

This commit is contained in:
Alex Dima 2017-10-24 18:30:11 +02:00
parent 6a133b2af2
commit 5d3dfe86cd
3 changed files with 6 additions and 3 deletions

View file

@ -17,7 +17,7 @@ export class TrimTrailingWhitespaceCommand implements editorCommon.ICommand {
private selectionId: string;
private cursors: Position[];
constructor(selection: Selection, cursors: Position[] = []) {
constructor(selection: Selection, cursors: Position[]) {
this.selection = selection;
this.cursors = cursors;
}

View file

@ -209,8 +209,11 @@ export class TrimTrailingWhitespaceAction extends EditorAction {
public run(accessor: ServicesAccessor, editor: ICommonCodeEditor, args: any): void {
var cursors: Position[];
let cursors: Position[] = [];
if (args.reason === 'auto-save') {
// See https://github.com/editorconfig/editorconfig-vscode/issues/47
// It is very convenient for the editor config extension to invoke this action.
// So, if we get a reason:'auto-save' passed in, let's preserve cursor positions.
cursors = editor.getSelections().map(s => new Position(s.positionLineNumber, s.positionColumn));
}

View file

@ -14,7 +14,7 @@ import { withEditorModel } from 'vs/editor/test/common/editorTestUtils';
function assertTrimTrailingWhitespaceCommand(text: string[], expected: IIdentifiedSingleEditOperation[]): void {
return withEditorModel(text, (model) => {
var op = new TrimTrailingWhitespaceCommand(new Selection(1, 1, 1, 1));
var op = new TrimTrailingWhitespaceCommand(new Selection(1, 1, 1, 1), []);
var actual = getEditOperation(model, op);
assert.deepEqual(actual, expected);
});