Skip to content

Commit 5d3dfe8

Browse files
committed
Remove optional argument, document reason for looking at args
1 parent 6a133b2 commit 5d3dfe8

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/vs/editor/common/commands/trimTrailingWhitespaceCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class TrimTrailingWhitespaceCommand implements editorCommon.ICommand {
1717
private selectionId: string;
1818
private cursors: Position[];
1919

20-
constructor(selection: Selection, cursors: Position[] = []) {
20+
constructor(selection: Selection, cursors: Position[]) {
2121
this.selection = selection;
2222
this.cursors = cursors;
2323
}

src/vs/editor/contrib/linesOperations/common/linesOperations.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,11 @@ export class TrimTrailingWhitespaceAction extends EditorAction {
209209

210210
public run(accessor: ServicesAccessor, editor: ICommonCodeEditor, args: any): void {
211211

212-
var cursors: Position[];
212+
let cursors: Position[] = [];
213213
if (args.reason === 'auto-save') {
214+
// See https://github.com/editorconfig/editorconfig-vscode/issues/47
215+
// It is very convenient for the editor config extension to invoke this action.
216+
// So, if we get a reason:'auto-save' passed in, let's preserve cursor positions.
214217
cursors = editor.getSelections().map(s => new Position(s.positionLineNumber, s.positionColumn));
215218
}
216219

src/vs/editor/test/common/commands/trimTrailingWhitespaceCommand.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { withEditorModel } from 'vs/editor/test/common/editorTestUtils';
1414

1515
function assertTrimTrailingWhitespaceCommand(text: string[], expected: IIdentifiedSingleEditOperation[]): void {
1616
return withEditorModel(text, (model) => {
17-
var op = new TrimTrailingWhitespaceCommand(new Selection(1, 1, 1, 1));
17+
var op = new TrimTrailingWhitespaceCommand(new Selection(1, 1, 1, 1), []);
1818
var actual = getEditOperation(model, op);
1919
assert.deepEqual(actual, expected);
2020
});

0 commit comments

Comments
 (0)