Skip to content

Commit

Permalink
var -> let, const
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed May 19, 2017
1 parent ada3874 commit 0930016
Showing 1 changed file with 50 additions and 52 deletions.
102 changes: 50 additions & 52 deletions src/vs/editor/common/controller/cursorCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ export class CursorCollection {
return result;
}

private _getAll(): OneCursor[] {
var result: OneCursor[] = [];
result.push(this.primaryCursor);
result = result.concat(this.secondaryCursors);
return result;
}

public getAll(): CursorState[] {
let result: CursorState[] = [];
result[0] = this.primaryCursor.asCursorState();
Expand All @@ -68,37 +61,37 @@ export class CursorCollection {
}

public getPositions(): Position[] {
var result: Position[] = [];
result.push(this.primaryCursor.modelState.position);
for (var i = 0, len = this.secondaryCursors.length; i < len; i++) {
result.push(this.secondaryCursors[i].modelState.position);
let result: Position[] = [];
result[0] = this.primaryCursor.modelState.position;
for (let i = 0, len = this.secondaryCursors.length; i < len; i++) {
result[i + 1] = this.secondaryCursors[i].modelState.position;
}
return result;
}

public getViewPositions(): Position[] {
var result: Position[] = [];
result.push(this.primaryCursor.viewState.position);
for (var i = 0, len = this.secondaryCursors.length; i < len; i++) {
result.push(this.secondaryCursors[i].viewState.position);
let result: Position[] = [];
result[0] = this.primaryCursor.viewState.position;
for (let i = 0, len = this.secondaryCursors.length; i < len; i++) {
result[i + 1] = this.secondaryCursors[i].viewState.position;
}
return result;
}

public getSelections(): Selection[] {
var result: Selection[] = [];
result.push(this.primaryCursor.modelState.selection);
for (var i = 0, len = this.secondaryCursors.length; i < len; i++) {
result.push(this.secondaryCursors[i].modelState.selection);
let result: Selection[] = [];
result[0] = this.primaryCursor.modelState.selection;
for (let i = 0, len = this.secondaryCursors.length; i < len; i++) {
result[i + 1] = this.secondaryCursors[i].modelState.selection;
}
return result;
}

public getViewSelections(): Selection[] {
var result: Selection[] = [];
result.push(this.primaryCursor.viewState.selection);
for (var i = 0, len = this.secondaryCursors.length; i < len; i++) {
result.push(this.secondaryCursors[i].viewState.selection);
let result: Selection[] = [];
result[0] = this.primaryCursor.viewState.selection;
for (let i = 0, len = this.secondaryCursors.length; i < len; i++) {
result[i + 1] = this.secondaryCursors[i].viewState.selection;
}
return result;
}
Expand Down Expand Up @@ -147,13 +140,8 @@ export class CursorCollection {
this._setSecondaryStates([]);
}

public normalize(): void {
this._mergeCursorsIfNecessary();
}

private _addSecondaryCursor(): void {
var newCursor = new OneCursor(this.context);
this.secondaryCursors.push(newCursor);
this.secondaryCursors.push(new OneCursor(this.context));
this.lastAddedCursorIndex = this.secondaryCursors.length;
}

Expand All @@ -172,55 +160,65 @@ export class CursorCollection {
this.secondaryCursors.splice(removeIndex, 1);
}

private _mergeCursorsIfNecessary(): void {
private _getAll(): OneCursor[] {
let result: OneCursor[] = [];
result[0] = this.primaryCursor;
for (let i = 0, len = this.secondaryCursors.length; i < len; i++) {
result[i + 1] = this.secondaryCursors[i];
}
return result;
}

public normalize(): void {
if (this.secondaryCursors.length === 0) {
return;
}
var cursors = this._getAll();
var sortedCursors: {
let cursors = this._getAll();

interface SortedCursor {
index: number;
selection: Selection;
viewSelection: Selection;
}[] = [];
for (var i = 0; i < cursors.length; i++) {
}
let sortedCursors: SortedCursor[] = [];
for (let i = 0, len = cursors.length; i < len; i++) {
sortedCursors.push({
index: i,
selection: cursors[i].modelState.selection,
viewSelection: cursors[i].viewState.selection
});
}

sortedCursors.sort((a, b) => {
if (a.viewSelection.startLineNumber === b.viewSelection.startLineNumber) {
return a.viewSelection.startColumn - b.viewSelection.startColumn;
}
return a.viewSelection.startLineNumber - b.viewSelection.startLineNumber;
});

for (var sortedCursorIndex = 0; sortedCursorIndex < sortedCursors.length - 1; sortedCursorIndex++) {
var current = sortedCursors[sortedCursorIndex];
var next = sortedCursors[sortedCursorIndex + 1];
for (let sortedCursorIndex = 0; sortedCursorIndex < sortedCursors.length - 1; sortedCursorIndex++) {
const current = sortedCursors[sortedCursorIndex];
const next = sortedCursors[sortedCursorIndex + 1];

var currentViewSelection = current.viewSelection;
var nextViewSelection = next.viewSelection;
const currentViewSelection = current.viewSelection;
const nextViewSelection = next.viewSelection;

if (nextViewSelection.getStartPosition().isBeforeOrEqual(currentViewSelection.getEndPosition())) {
var winnerSortedCursorIndex = current.index < next.index ? sortedCursorIndex : sortedCursorIndex + 1;
var looserSortedCursorIndex = current.index < next.index ? sortedCursorIndex + 1 : sortedCursorIndex;
const winnerSortedCursorIndex = current.index < next.index ? sortedCursorIndex : sortedCursorIndex + 1;
const looserSortedCursorIndex = current.index < next.index ? sortedCursorIndex + 1 : sortedCursorIndex;

var looserIndex = sortedCursors[looserSortedCursorIndex].index;
var winnerIndex = sortedCursors[winnerSortedCursorIndex].index;
const looserIndex = sortedCursors[looserSortedCursorIndex].index;
const winnerIndex = sortedCursors[winnerSortedCursorIndex].index;

var looserSelection = sortedCursors[looserSortedCursorIndex].selection;
var winnerSelection = sortedCursors[winnerSortedCursorIndex].selection;
const looserSelection = sortedCursors[looserSortedCursorIndex].selection;
const winnerSelection = sortedCursors[winnerSortedCursorIndex].selection;

if (!looserSelection.equalsSelection(winnerSelection)) {
var resultingRange = looserSelection.plusRange(winnerSelection);
var looserSelectionIsLTR = (looserSelection.selectionStartLineNumber === looserSelection.startLineNumber && looserSelection.selectionStartColumn === looserSelection.startColumn);
var winnerSelectionIsLTR = (winnerSelection.selectionStartLineNumber === winnerSelection.startLineNumber && winnerSelection.selectionStartColumn === winnerSelection.startColumn);
const resultingRange = looserSelection.plusRange(winnerSelection);
const looserSelectionIsLTR = (looserSelection.selectionStartLineNumber === looserSelection.startLineNumber && looserSelection.selectionStartColumn === looserSelection.startColumn);
const winnerSelectionIsLTR = (winnerSelection.selectionStartLineNumber === winnerSelection.startLineNumber && winnerSelection.selectionStartColumn === winnerSelection.startColumn);

// Give more importance to the last added cursor (think Ctrl-dragging + hitting another cursor)
var resultingSelectionIsLTR: boolean;
let resultingSelectionIsLTR: boolean;
if (looserIndex === this.lastAddedCursorIndex) {
resultingSelectionIsLTR = looserSelectionIsLTR;
this.lastAddedCursorIndex = winnerIndex;
Expand All @@ -229,7 +227,7 @@ export class CursorCollection {
resultingSelectionIsLTR = winnerSelectionIsLTR;
}

var resultingSelection: Selection;
let resultingSelection: Selection;
if (resultingSelectionIsLTR) {
resultingSelection = new Selection(resultingRange.startLineNumber, resultingRange.startColumn, resultingRange.endLineNumber, resultingRange.endColumn);
} else {
Expand All @@ -241,7 +239,7 @@ export class CursorCollection {
cursors[winnerIndex].setState(this.context, resultingState.modelState, resultingState.viewState);
}

for (var j = 0; j < sortedCursors.length; j++) {
for (let j = 0; j < sortedCursors.length; j++) {
if (sortedCursors[j].index > looserIndex) {
sortedCursors[j].index--;
}
Expand Down

0 comments on commit 0930016

Please sign in to comment.