Skip to content

Commit

Permalink
Extract IModelLine (#30180)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Jul 6, 2017
1 parent 46057d3 commit c851d5d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/vs/editor/common/model/editableTextModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { Range, IRange } from 'vs/editor/common/core/range';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { EditStack } from 'vs/editor/common/model/editStack';
import { ILineEdit, LineMarker, ModelLine, MarkersTracker } from 'vs/editor/common/model/modelLine';
import { ILineEdit, LineMarker, ModelLine, MarkersTracker, IModelLine } from 'vs/editor/common/model/modelLine';
import { TextModelWithDecorations, ModelDecorationOptions } from 'vs/editor/common/model/textModelWithDecorations';
import * as strings from 'vs/base/common/strings';
import * as arrays from 'vs/base/common/arrays';
Expand Down Expand Up @@ -649,7 +649,7 @@ export class EditableTextModel extends TextModelWithDecorations implements edito
this._invalidateLine(spliceLineNumber - 1);

// Lines in the middle
let newLines: ModelLine[] = [];
let newLines: IModelLine[] = [];
let newLinesContent: string[] = [];
let newLinesLengths = new Uint32Array(insertingLinesCnt - editingLinesCnt);
for (let j = editingLinesCnt + 1; j <= insertingLinesCnt; j++) {
Expand Down
31 changes: 30 additions & 1 deletion src/vs/editor/common/model/modelLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,36 @@ function computePlusOneIndentLevel(line: string, tabSize: number): number {
return indent + 1;
}

export class ModelLine {
export interface IModelLine {
readonly text: string;
isInvalid: boolean;

// --- markers
addMarker(marker: LineMarker): void;
addMarkers(markers: LineMarker[]): void;
removeMarker(marker: LineMarker): void;
removeMarkers(deleteMarkers: { [markerId: string]: boolean; }): void;
getMarkers(): LineMarker[];

// --- tokenization
resetTokenizationState(): void;
getState(): IState;
setState(state: IState): void;
getTokens(topLevelLanguageId: LanguageId): LineTokens;
setTokens(topLevelLanguageId: LanguageId, tokens: Uint32Array): void;

// --- indentation
updateTabSize(tabSize: number): void;
getIndentLevel(): number;

// --- editing
updateLineNumber(markersTracker: MarkersTracker, newLineNumber: number): void;
applyEdits(markersTracker: MarkersTracker, edits: ILineEdit[], tabSize: number): number;
append(markersTracker: MarkersTracker, myLineNumber: number, other: ModelLine, tabSize: number): void;
split(markersTracker: MarkersTracker, splitColumn: number, forceMoveMarkers: boolean, tabSize: number): ModelLine;
}

export class ModelLine implements IModelLine {

private _text: string;
public get text(): string { return this._text; }
Expand Down
6 changes: 3 additions & 3 deletions src/vs/editor/common/model/textModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as strings from 'vs/base/common/strings';
import { Position, IPosition } from 'vs/editor/common/core/position';
import { Range, IRange } from 'vs/editor/common/core/range';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { ModelLine } from 'vs/editor/common/model/modelLine';
import { ModelLine, IModelLine } from 'vs/editor/common/model/modelLine';
import { guessIndentation } from 'vs/editor/common/model/indentationGuesser';
import { EDITOR_MODEL_DEFAULTS } from 'vs/editor/common/config/editorOptions';
import { PrefixSumComputer } from 'vs/editor/common/viewModel/prefixSumComputer';
Expand Down Expand Up @@ -76,7 +76,7 @@ export class TextModel implements editorCommon.ITextModel {

protected readonly _eventEmitter: OrderGuaranteeEventEmitter;

/*protected*/ _lines: ModelLine[];
/*protected*/ _lines: IModelLine[];
protected _EOL: string;
protected _isDisposed: boolean;
protected _isDisposing: boolean;
Expand Down Expand Up @@ -756,7 +756,7 @@ export class TextModel implements editorCommon.ITextModel {
private _constructLines(textSource: ITextSource): void {
const tabSize = this._options.tabSize;
let rawLines = textSource.lines;
let modelLines: ModelLine[] = [];
let modelLines: IModelLine[] = [];

for (let i = 0, len = rawLines.length; i < len; i++) {
modelLines[i] = new ModelLine(rawLines[i], tabSize);
Expand Down

0 comments on commit c851d5d

Please sign in to comment.