Skip to content

Commit

Permalink
Remove ModelLine._lineNumber (#30180)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Jul 6, 2017
1 parent 1b982d3 commit 93d755c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 32 deletions.
7 changes: 1 addition & 6 deletions src/vs/editor/common/model/editableTextModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,7 @@ export class EditableTextModel extends TextModelWithDecorations implements edito
let newLinesContent: string[] = [];
let newLinesLengths = new Uint32Array(insertingLinesCnt - editingLinesCnt);
for (let j = editingLinesCnt + 1; j <= insertingLinesCnt; j++) {
let newLineNumber = startLineNumber + j;
newLines.push(new ModelLine(newLineNumber, op.lines[j], tabSize));
newLines.push(new ModelLine(op.lines[j], tabSize));
newLinesContent.push(op.lines[j]);
newLinesLengths[j - editingLinesCnt - 1] = op.lines[j].length + this._EOL.length;
}
Expand Down Expand Up @@ -729,10 +728,6 @@ export class EditableTextModel extends TextModelWithDecorations implements edito
let line = this._lines[i];
let lineNumber = i + 1;

if (line.lineNumber !== lineNumber) {
throw new Error('Invalid lineNumber at line: ' + lineNumber + '; text is: ' + this.getValue());
}

let markers = line.getMarkers();
if (markers !== null) {
for (let j = 0, lenJ = markers.length; j < lenJ; j++) {
Expand Down
12 changes: 2 additions & 10 deletions src/vs/editor/common/model/modelLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ function computePlusOneIndentLevel(line: string, tabSize: number): number {
}

export class ModelLine {
private _lineNumber: number;
public get lineNumber(): number { return this._lineNumber; }

private _text: string;
public get text(): string { return this._text; }
Expand Down Expand Up @@ -205,8 +203,7 @@ export class ModelLine {
private _lineTokens: ArrayBuffer;
private _markers: LineMarker[];

constructor(lineNumber: number, text: string, tabSize: number) {
this._lineNumber = lineNumber | 0;
constructor(text: string, tabSize: number) {
this._metadata = 0;
this._setText(text, tabSize);
this._state = null;
Expand Down Expand Up @@ -607,7 +604,7 @@ export class ModelLine {
// Mark overflowing tokens for deletion & delete marked tokens
this._deleteMarkedTokens(this._markOverflowingTokensForDeletion(0, this._text.length));

var otherLine = new ModelLine(this._lineNumber + 1, otherText, tabSize);
var otherLine = new ModelLine(otherText, tabSize);
if (otherMarkers) {
otherLine.addMarkers(otherMarkers);
}
Expand Down Expand Up @@ -727,18 +724,13 @@ export class ModelLine {
}

public updateLineNumber(markersTracker: MarkersTracker, newLineNumber: number): void {
if (this._lineNumber === newLineNumber) {
return;
}
if (this._markers) {
let markers = this._markers;
for (let i = 0, len = markers.length; i < len; i++) {
let marker = markers[i];
marker.updateLineNumber(markersTracker, newLineNumber);
}
}

this._lineNumber = newLineNumber;
}

private _indexOfMarkerId(markerId: string): number {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/common/model/textModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ export class TextModel implements editorCommon.ITextModel {
let modelLines: ModelLine[] = [];

for (let i = 0, len = rawLines.length; i < len; i++) {
modelLines[i] = new ModelLine(i + 1, rawLines[i], tabSize);
modelLines[i] = new ModelLine(rawLines[i], tabSize);
}
this._BOM = textSource.BOM;
this._mightContainRTL = textSource.containsRTL;
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/test/common/commands/sideEditing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function testCommand(lines: string[], selections: Selection[], edits: IIdentifie
}

function testLineEditMarker(text: string, column: number, stickToPreviousCharacter: boolean, edit: ILineEdit, expectedColumn: number): void {
var line = new ModelLine(1, text, NO_TAB_SIZE);
var line = new ModelLine(text, NO_TAB_SIZE);
line.addMarker(new LineMarker('1', 0, new Position(0, column), stickToPreviousCharacter));

line.applyEdits(new MarkersTracker(), [edit], NO_TAB_SIZE);
Expand Down
28 changes: 14 additions & 14 deletions src/vs/editor/test/common/model/model.line.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const NO_TAB_SIZE = 0;

suite('ModelLine - getIndentLevel', () => {
function assertIndentLevel(text: string, expected: number, tabSize: number = 4): void {
let modelLine = new ModelLine(1, text, tabSize);
let modelLine = new ModelLine(text, tabSize);
let actual = modelLine.getIndentLevel();
assert.equal(actual, expected, text);
}
Expand All @@ -53,7 +53,7 @@ suite('ModelLine - getIndentLevel', () => {
suite('Editor Model - modelLine.applyEdits text', () => {

function testEdits(initial: string, edits: ILineEdit[], expected: string): void {
var line = new ModelLine(1, initial, NO_TAB_SIZE);
var line = new ModelLine(initial, NO_TAB_SIZE);
line.applyEdits(new MarkersTracker(), edits, NO_TAB_SIZE);
assert.equal(line.text, expected);
}
Expand Down Expand Up @@ -200,7 +200,7 @@ suite('Editor Model - modelLine.applyEdits text', () => {
suite('Editor Model - modelLine.split text', () => {

function testLineSplit(initial: string, splitColumn: number, expected1: string, expected2: string): void {
var line = new ModelLine(1, initial, NO_TAB_SIZE);
var line = new ModelLine(initial, NO_TAB_SIZE);
var newLine = line.split(new MarkersTracker(), splitColumn, false, NO_TAB_SIZE);
assert.equal(line.text, expected1);
assert.equal(newLine.text, expected2);
Expand Down Expand Up @@ -237,8 +237,8 @@ suite('Editor Model - modelLine.split text', () => {
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);
var line1 = new ModelLine(a, NO_TAB_SIZE);
var line2 = new ModelLine(b, NO_TAB_SIZE);
line1.append(new MarkersTracker(), 1, line2, NO_TAB_SIZE);
assert.equal(line1.text, expected);
}
Expand Down Expand Up @@ -298,7 +298,7 @@ suite('Editor Model - modelLine.applyEdits text & tokens', () => {


function testLineEditTokens(initialText: string, initialTokens: TestToken[], edits: ILineEdit[], expectedText: string, expectedTokens: TestToken[]): void {
let line = new ModelLine(1, initialText, NO_TAB_SIZE);
let line = new ModelLine(initialText, NO_TAB_SIZE);
line.setTokens(0, TestToken.toTokens(initialTokens));

line.applyEdits(new MarkersTracker(), edits, NO_TAB_SIZE);
Expand All @@ -308,7 +308,7 @@ suite('Editor Model - modelLine.applyEdits text & tokens', () => {
}

test('insertion on empty line', () => {
let line = new ModelLine(1, 'some text', NO_TAB_SIZE);
let line = new ModelLine('some text', NO_TAB_SIZE);
line.setTokens(0, TestToken.toTokens([new TestToken(0, 1)]));

line.applyEdits(new MarkersTracker(), [{ startColumn: 1, endColumn: 10, text: '', forceMoveMarkers: false }], NO_TAB_SIZE);
Expand Down Expand Up @@ -870,7 +870,7 @@ suite('Editor Model - modelLine.applyEdits text & tokens', () => {

suite('Editor Model - modelLine.split text & tokens', () => {
function testLineSplitTokens(initialText: string, initialTokens: TestToken[], splitColumn: number, expectedText1: string, expectedText2: string, expectedTokens: TestToken[]): void {
let line = new ModelLine(1, initialText, NO_TAB_SIZE);
let line = new ModelLine(initialText, NO_TAB_SIZE);
line.setTokens(0, TestToken.toTokens(initialTokens));

let other = line.split(new MarkersTracker(), splitColumn, false, NO_TAB_SIZE);
Expand Down Expand Up @@ -954,10 +954,10 @@ suite('Editor Model - modelLine.split text & tokens', () => {

suite('Editor Model - modelLine.append text & tokens', () => {
function testLineAppendTokens(aText: string, aTokens: TestToken[], bText: string, bTokens: TestToken[], expectedText: string, expectedTokens: TestToken[]): void {
let a = new ModelLine(1, aText, NO_TAB_SIZE);
let a = new ModelLine(aText, NO_TAB_SIZE);
a.setTokens(0, TestToken.toTokens(aTokens));

let b = new ModelLine(2, bText, NO_TAB_SIZE);
let b = new ModelLine(bText, NO_TAB_SIZE);
b.setTokens(0, TestToken.toTokens(bTokens));

a.append(new MarkersTracker(), 1, b, NO_TAB_SIZE);
Expand Down Expand Up @@ -1094,7 +1094,7 @@ suite('Editor Model - modelLine.applyEdits text & markers', () => {
}

function testLineEditMarkers(initialText: string, initialMarkers: LineMarker[], edits: ILineEdit[], expectedText: string, expectedChangedMarkers: number[], _expectedMarkers: LineMarker[]): void {
let line = new ModelLine(1, initialText, NO_TAB_SIZE);
let line = new ModelLine(initialText, NO_TAB_SIZE);
line.addMarkers(initialMarkers);

let changedMarkers = new MarkersTracker();
Expand Down Expand Up @@ -1911,7 +1911,7 @@ suite('Editor Model - modelLine.split text & markers', () => {
}

function testLineSplitMarkers(initialText: string, initialMarkers: LineMarker[], splitColumn: number, forceMoveMarkers: boolean, expectedText1: string, expectedText2: string, expectedChangedMarkers: number[], _expectedMarkers1: LineMarker[], _expectedMarkers2: LineMarker[]): void {
let line = new ModelLine(1, initialText, NO_TAB_SIZE);
let line = new ModelLine(initialText, NO_TAB_SIZE);
line.addMarkers(initialMarkers);

let changedMarkers = new MarkersTracker();
Expand Down Expand Up @@ -2184,10 +2184,10 @@ suite('Editor Model - modelLine.append text & markers', () => {
}

function testLinePrependMarkers(aText: string, aMarkers: LineMarker[], bText: string, bMarkers: LineMarker[], expectedText: string, expectedChangedMarkers: number[], _expectedMarkers: LineMarker[]): void {
let a = new ModelLine(1, aText, NO_TAB_SIZE);
let a = new ModelLine(aText, NO_TAB_SIZE);
a.addMarkers(aMarkers);

let b = new ModelLine(2, bText, NO_TAB_SIZE);
let b = new ModelLine(bText, NO_TAB_SIZE);
b.addMarkers(bMarkers);

let changedMarkers = new MarkersTracker();
Expand Down

0 comments on commit 93d755c

Please sign in to comment.