提交 6a133b2a 编写于 作者: D David Gileadi

#24400 pass cursors, not boolean

上级 e0e6c47b
......@@ -15,20 +15,15 @@ export class TrimTrailingWhitespaceCommand implements editorCommon.ICommand {
private selection: Selection;
private selectionId: string;
private preserveCursor: boolean;
private cursors: Position[];
constructor(selection: Selection, preserveCursor?: boolean) {
constructor(selection: Selection, cursors: Position[] = []) {
this.selection = selection;
this.preserveCursor = preserveCursor;
this.cursors = cursors;
}
public getEditOperations(model: editorCommon.ITokenizedModel, builder: editorCommon.IEditOperationBuilder): void {
var cursors: [Position];
if (this.selection && this.preserveCursor) {
cursors = [new Position(this.selection.positionLineNumber, this.selection.positionColumn)];
}
let ops = trimTrailingWhitespace(model, cursors || []);
let ops = trimTrailingWhitespace(model, this.cursors);
for (let i = 0, len = ops.length; i < len; i++) {
let op = ops[i];
......
......@@ -14,6 +14,7 @@ import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { ReplaceCommand, ReplaceCommandThatPreservesSelection } from 'vs/editor/common/commands/replaceCommand';
import { Range } from 'vs/editor/common/core/range';
import { Selection } from 'vs/editor/common/core/selection';
import { Position } from 'vs/editor/common/core/position';
import { editorAction, ServicesAccessor, IActionOptions, EditorAction } from 'vs/editor/common/editorCommonExtensions';
import { CopyLinesCommand } from './copyLinesCommand';
import { DeleteLinesCommand } from './deleteLinesCommand';
......@@ -208,9 +209,12 @@ export class TrimTrailingWhitespaceAction extends EditorAction {
public run(accessor: ServicesAccessor, editor: ICommonCodeEditor, args: any): void {
let preserveCursor: boolean = (args.reason === 'auto-save');
var cursors: Position[];
if (args.reason === 'auto-save') {
cursors = editor.getSelections().map(s => new Position(s.positionLineNumber, s.positionColumn));
}
var command = new TrimTrailingWhitespaceCommand(editor.getSelection(), preserveCursor);
var command = new TrimTrailingWhitespaceCommand(editor.getSelection(), cursors);
editor.pushUndoStop();
editor.executeCommands(this.id, [command]);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册