From 1b982d36ad0425f1c81e7780441dc51e32b927c7 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Thu, 6 Jul 2017 11:20:09 +0200 Subject: [PATCH] Eliminate ModelLine._lineNumber usage in ModelLine.append (#30180) --- src/vs/editor/common/model/editableTextModel.ts | 6 +++--- src/vs/editor/common/model/modelLine.ts | 4 ++-- src/vs/editor/test/common/model/model.line.test.ts | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/vs/editor/common/model/editableTextModel.ts b/src/vs/editor/common/model/editableTextModel.ts index 34f1fdfe8043d..1597d459ffc04 100644 --- a/src/vs/editor/common/model/editableTextModel.ts +++ b/src/vs/editor/common/model/editableTextModel.ts @@ -603,7 +603,7 @@ export class EditableTextModel extends TextModelWithDecorations implements edito } // Reconstruct first line - this._lines[spliceStartLineNumber - 1].append(markersTracker, endLineRemains, tabSize); + this._lines[spliceStartLineNumber - 1].append(markersTracker, spliceStartLineNumber, endLineRemains, tabSize); if (this._lineStarts) { // update prefix sum this._lineStarts.changeValue(spliceStartLineNumber - 1, this._lines[spliceStartLineNumber - 1].text.length + this._EOL.length); @@ -666,7 +666,7 @@ export class EditableTextModel extends TextModelWithDecorations implements edito } // Last line - this._lines[startLineNumber + insertingLinesCnt - 1].append(markersTracker, leftoverLine, tabSize); + this._lines[startLineNumber + insertingLinesCnt - 1].append(markersTracker, startLineNumber + insertingLinesCnt, leftoverLine, tabSize); if (this._lineStarts) { // update prefix sum this._lineStarts.changeValue(startLineNumber + insertingLinesCnt - 1, this._lines[startLineNumber + insertingLinesCnt - 1].text.length + this._EOL.length); @@ -739,7 +739,7 @@ export class EditableTextModel extends TextModelWithDecorations implements edito foundMarkersCnt++; let markerId = markers[j].id; let marker = this._markerIdToMarker[markerId]; - if (marker.position.lineNumber !== line.lineNumber) { + if (marker.position.lineNumber !== lineNumber) { throw new Error('Misplaced marker with id ' + markerId); } } diff --git a/src/vs/editor/common/model/modelLine.ts b/src/vs/editor/common/model/modelLine.ts index 4a1b012f60d00..53842a0af3d99 100644 --- a/src/vs/editor/common/model/modelLine.ts +++ b/src/vs/editor/common/model/modelLine.ts @@ -614,7 +614,7 @@ export class ModelLine { return otherLine; } - public append(markersTracker: MarkersTracker, other: ModelLine, tabSize: number): void { + public append(markersTracker: MarkersTracker, myLineNumber: number, other: ModelLine, tabSize: number): void { // console.log('--> append: THIS :: ' + this._printMarkers()); // console.log('--> append: OTHER :: ' + this._printMarkers()); let thisTextLength = this._text.length; @@ -656,7 +656,7 @@ export class ModelLine { for (let i = 0, len = otherMarkers.length; i < len; i++) { let marker = otherMarkers[i]; - marker.updatePosition(markersTracker, new Position(this._lineNumber, marker.position.column + thisTextLength)); + marker.updatePosition(markersTracker, new Position(myLineNumber, marker.position.column + thisTextLength)); } this.addMarkers(otherMarkers); diff --git a/src/vs/editor/test/common/model/model.line.test.ts b/src/vs/editor/test/common/model/model.line.test.ts index 0225ee97d350d..7f690356c28fc 100644 --- a/src/vs/editor/test/common/model/model.line.test.ts +++ b/src/vs/editor/test/common/model/model.line.test.ts @@ -239,7 +239,7 @@ suite('Editor Model - modelLine.append text', () => { function testLineAppend(a: string, b: string, expected: string): void { var line1 = new ModelLine(1, a, NO_TAB_SIZE); var line2 = new ModelLine(2, b, NO_TAB_SIZE); - line1.append(new MarkersTracker(), line2, NO_TAB_SIZE); + line1.append(new MarkersTracker(), 1, line2, NO_TAB_SIZE); assert.equal(line1.text, expected); } @@ -960,7 +960,7 @@ suite('Editor Model - modelLine.append text & tokens', () => { let b = new ModelLine(2, bText, NO_TAB_SIZE); b.setTokens(0, TestToken.toTokens(bTokens)); - a.append(new MarkersTracker(), b, NO_TAB_SIZE); + a.append(new MarkersTracker(), 1, b, NO_TAB_SIZE); assert.equal(a.text, expectedText); assertLineTokens(a.getTokens(0), expectedTokens); @@ -2191,7 +2191,7 @@ suite('Editor Model - modelLine.append text & markers', () => { b.addMarkers(bMarkers); let changedMarkers = new MarkersTracker(); - a.append(changedMarkers, b, NO_TAB_SIZE); + a.append(changedMarkers, 1, b, NO_TAB_SIZE); assert.equal(a.text, expectedText, 'text');