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

var -> let, const

上级 ada3874b
...@@ -51,13 +51,6 @@ export class CursorCollection { ...@@ -51,13 +51,6 @@ export class CursorCollection {
return result; return result;
} }
private _getAll(): OneCursor[] {
var result: OneCursor[] = [];
result.push(this.primaryCursor);
result = result.concat(this.secondaryCursors);
return result;
}
public getAll(): CursorState[] { public getAll(): CursorState[] {
let result: CursorState[] = []; let result: CursorState[] = [];
result[0] = this.primaryCursor.asCursorState(); result[0] = this.primaryCursor.asCursorState();
...@@ -68,37 +61,37 @@ export class CursorCollection { ...@@ -68,37 +61,37 @@ export class CursorCollection {
} }
public getPositions(): Position[] { public getPositions(): Position[] {
var result: Position[] = []; let result: Position[] = [];
result.push(this.primaryCursor.modelState.position); result[0] = this.primaryCursor.modelState.position;
for (var i = 0, len = this.secondaryCursors.length; i < len; i++) { for (let i = 0, len = this.secondaryCursors.length; i < len; i++) {
result.push(this.secondaryCursors[i].modelState.position); result[i + 1] = this.secondaryCursors[i].modelState.position;
} }
return result; return result;
} }
public getViewPositions(): Position[] { public getViewPositions(): Position[] {
var result: Position[] = []; let result: Position[] = [];
result.push(this.primaryCursor.viewState.position); result[0] = this.primaryCursor.viewState.position;
for (var i = 0, len = this.secondaryCursors.length; i < len; i++) { for (let i = 0, len = this.secondaryCursors.length; i < len; i++) {
result.push(this.secondaryCursors[i].viewState.position); result[i + 1] = this.secondaryCursors[i].viewState.position;
} }
return result; return result;
} }
public getSelections(): Selection[] { public getSelections(): Selection[] {
var result: Selection[] = []; let result: Selection[] = [];
result.push(this.primaryCursor.modelState.selection); result[0] = this.primaryCursor.modelState.selection;
for (var i = 0, len = this.secondaryCursors.length; i < len; i++) { for (let i = 0, len = this.secondaryCursors.length; i < len; i++) {
result.push(this.secondaryCursors[i].modelState.selection); result[i + 1] = this.secondaryCursors[i].modelState.selection;
} }
return result; return result;
} }
public getViewSelections(): Selection[] { public getViewSelections(): Selection[] {
var result: Selection[] = []; let result: Selection[] = [];
result.push(this.primaryCursor.viewState.selection); result[0] = this.primaryCursor.viewState.selection;
for (var i = 0, len = this.secondaryCursors.length; i < len; i++) { for (let i = 0, len = this.secondaryCursors.length; i < len; i++) {
result.push(this.secondaryCursors[i].viewState.selection); result[i + 1] = this.secondaryCursors[i].viewState.selection;
} }
return result; return result;
} }
...@@ -147,13 +140,8 @@ export class CursorCollection { ...@@ -147,13 +140,8 @@ export class CursorCollection {
this._setSecondaryStates([]); this._setSecondaryStates([]);
} }
public normalize(): void {
this._mergeCursorsIfNecessary();
}
private _addSecondaryCursor(): void { private _addSecondaryCursor(): void {
var newCursor = new OneCursor(this.context); this.secondaryCursors.push(new OneCursor(this.context));
this.secondaryCursors.push(newCursor);
this.lastAddedCursorIndex = this.secondaryCursors.length; this.lastAddedCursorIndex = this.secondaryCursors.length;
} }
...@@ -172,24 +160,34 @@ export class CursorCollection { ...@@ -172,24 +160,34 @@ export class CursorCollection {
this.secondaryCursors.splice(removeIndex, 1); 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) { if (this.secondaryCursors.length === 0) {
return; return;
} }
var cursors = this._getAll(); let cursors = this._getAll();
var sortedCursors: {
interface SortedCursor {
index: number; index: number;
selection: Selection; selection: Selection;
viewSelection: 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({ sortedCursors.push({
index: i, index: i,
selection: cursors[i].modelState.selection, selection: cursors[i].modelState.selection,
viewSelection: cursors[i].viewState.selection viewSelection: cursors[i].viewState.selection
}); });
} }
sortedCursors.sort((a, b) => { sortedCursors.sort((a, b) => {
if (a.viewSelection.startLineNumber === b.viewSelection.startLineNumber) { if (a.viewSelection.startLineNumber === b.viewSelection.startLineNumber) {
return a.viewSelection.startColumn - b.viewSelection.startColumn; return a.viewSelection.startColumn - b.viewSelection.startColumn;
...@@ -197,30 +195,30 @@ export class CursorCollection { ...@@ -197,30 +195,30 @@ export class CursorCollection {
return a.viewSelection.startLineNumber - b.viewSelection.startLineNumber; return a.viewSelection.startLineNumber - b.viewSelection.startLineNumber;
}); });
for (var sortedCursorIndex = 0; sortedCursorIndex < sortedCursors.length - 1; sortedCursorIndex++) { for (let sortedCursorIndex = 0; sortedCursorIndex < sortedCursors.length - 1; sortedCursorIndex++) {
var current = sortedCursors[sortedCursorIndex]; const current = sortedCursors[sortedCursorIndex];
var next = sortedCursors[sortedCursorIndex + 1]; const next = sortedCursors[sortedCursorIndex + 1];
var currentViewSelection = current.viewSelection; const currentViewSelection = current.viewSelection;
var nextViewSelection = next.viewSelection; const nextViewSelection = next.viewSelection;
if (nextViewSelection.getStartPosition().isBeforeOrEqual(currentViewSelection.getEndPosition())) { if (nextViewSelection.getStartPosition().isBeforeOrEqual(currentViewSelection.getEndPosition())) {
var winnerSortedCursorIndex = current.index < next.index ? sortedCursorIndex : sortedCursorIndex + 1; const winnerSortedCursorIndex = current.index < next.index ? sortedCursorIndex : sortedCursorIndex + 1;
var looserSortedCursorIndex = current.index < next.index ? sortedCursorIndex + 1 : sortedCursorIndex; const looserSortedCursorIndex = current.index < next.index ? sortedCursorIndex + 1 : sortedCursorIndex;
var looserIndex = sortedCursors[looserSortedCursorIndex].index; const looserIndex = sortedCursors[looserSortedCursorIndex].index;
var winnerIndex = sortedCursors[winnerSortedCursorIndex].index; const winnerIndex = sortedCursors[winnerSortedCursorIndex].index;
var looserSelection = sortedCursors[looserSortedCursorIndex].selection; const looserSelection = sortedCursors[looserSortedCursorIndex].selection;
var winnerSelection = sortedCursors[winnerSortedCursorIndex].selection; const winnerSelection = sortedCursors[winnerSortedCursorIndex].selection;
if (!looserSelection.equalsSelection(winnerSelection)) { if (!looserSelection.equalsSelection(winnerSelection)) {
var resultingRange = looserSelection.plusRange(winnerSelection); const resultingRange = looserSelection.plusRange(winnerSelection);
var looserSelectionIsLTR = (looserSelection.selectionStartLineNumber === looserSelection.startLineNumber && looserSelection.selectionStartColumn === looserSelection.startColumn); const looserSelectionIsLTR = (looserSelection.selectionStartLineNumber === looserSelection.startLineNumber && looserSelection.selectionStartColumn === looserSelection.startColumn);
var winnerSelectionIsLTR = (winnerSelection.selectionStartLineNumber === winnerSelection.startLineNumber && winnerSelection.selectionStartColumn === winnerSelection.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) // Give more importance to the last added cursor (think Ctrl-dragging + hitting another cursor)
var resultingSelectionIsLTR: boolean; let resultingSelectionIsLTR: boolean;
if (looserIndex === this.lastAddedCursorIndex) { if (looserIndex === this.lastAddedCursorIndex) {
resultingSelectionIsLTR = looserSelectionIsLTR; resultingSelectionIsLTR = looserSelectionIsLTR;
this.lastAddedCursorIndex = winnerIndex; this.lastAddedCursorIndex = winnerIndex;
...@@ -229,7 +227,7 @@ export class CursorCollection { ...@@ -229,7 +227,7 @@ export class CursorCollection {
resultingSelectionIsLTR = winnerSelectionIsLTR; resultingSelectionIsLTR = winnerSelectionIsLTR;
} }
var resultingSelection: Selection; let resultingSelection: Selection;
if (resultingSelectionIsLTR) { if (resultingSelectionIsLTR) {
resultingSelection = new Selection(resultingRange.startLineNumber, resultingRange.startColumn, resultingRange.endLineNumber, resultingRange.endColumn); resultingSelection = new Selection(resultingRange.startLineNumber, resultingRange.startColumn, resultingRange.endLineNumber, resultingRange.endColumn);
} else { } else {
...@@ -241,7 +239,7 @@ export class CursorCollection { ...@@ -241,7 +239,7 @@ export class CursorCollection {
cursors[winnerIndex].setState(this.context, resultingState.modelState, resultingState.viewState); 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) { if (sortedCursors[j].index > looserIndex) {
sortedCursors[j].index--; sortedCursors[j].index--;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册