Skip to content

Commit

Permalink
Revisit #29457. Auto select one more character if the selected whites…
Browse files Browse the repository at this point in the history
…paces are shrinked due to auto indent.
  • Loading branch information
rebornix committed Jun 29, 2017
1 parent b405e7c commit e99bdad
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/vs/editor/contrib/linesOperations/common/moveLinesCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ export class MoveLinesCommand implements ICommand {

private _selectionId: string;
private _moveEndPositionDown: boolean;
private _moveEndNewIndentLevel: number | undefined;
private _moveEndLineSelectionShrink: boolean;

constructor(selection: Selection, isMovingDown: boolean, autoIndent: boolean) {
this._selection = selection;
this._isMovingDown = isMovingDown;
this._autoIndent = autoIndent;
this._moveEndNewIndentLevel = undefined;
this._moveEndLineSelectionShrink = false;
}

public getEditOperations(model: ITokenizedModel, builder: IEditOperationBuilder): void {
Expand All @@ -46,11 +46,8 @@ export class MoveLinesCommand implements ICommand {
var s = this._selection;

if (s.startLineNumber < s.endLineNumber && s.endColumn === 1) {
// if we have auto indent turned on, the endColumn may be 1 when doing indentation adjustment.
if (!this.isAutoIndent(model, s)) {
this._moveEndPositionDown = true;
s = s.setEndPosition(s.endLineNumber - 1, model.getLineMaxColumn(s.endLineNumber - 1));
}
this._moveEndPositionDown = true;
s = s.setEndPosition(s.endLineNumber - 1, model.getLineMaxColumn(s.endLineNumber - 1));
}

let tabSize = model.getOptions().tabSize;
Expand Down Expand Up @@ -308,10 +305,10 @@ export class MoveLinesCommand implements ICommand {
if (newIndent !== originalIndent) {
builder.addEditOperation(new Range(i, 1, i, originalIndent.length + 1), newIndent);

if (i === s.endLineNumber && s.endColumn <= originalIndent.length + 1) {
if (i === s.endLineNumber && s.endColumn <= originalIndent.length + 1 && newIndent === '') {
// as users select part of the original indent white spaces
// when we adjust the indentation of endLine, we should adjust the cursor position as well.
this._moveEndNewIndentLevel = newIndent.length;
this._moveEndLineSelectionShrink = true;
}
}

Expand All @@ -325,8 +322,8 @@ export class MoveLinesCommand implements ICommand {
result = result.setEndPosition(result.endLineNumber + 1, 1);
}

if (this._moveEndNewIndentLevel !== undefined) {
result = result.setEndPosition(result.endLineNumber, this._moveEndNewIndentLevel + 1);
if (this._moveEndLineSelectionShrink) {
result = result.setEndPosition(result.endLineNumber, 2);
}

return result;
Expand Down

0 comments on commit e99bdad

Please sign in to comment.