提交 09300167 编写于 作者: A Alex Dima

var -> let, const

上级 ada3874b
......@@ -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();
......@@ -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;
}
......@@ -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;
}
......@@ -172,24 +160,34 @@ 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;
......@@ -197,30 +195,30 @@ export class CursorCollection {
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;
......@@ -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 {
......@@ -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--;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册