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

Remove unused code

上级 7b8f3088
......@@ -46,127 +46,6 @@ export function computeIndentLevel(line: string, tabSize: number): number {
return indent;
}
export interface IModelLine {
readonly text: string;
// --- editing
applyEdits(edits: ILineEdit[]): number;
append(other: IModelLine): void;
split(splitColumn: number): IModelLine;
}
export abstract class AbstractModelLine {
constructor() {
}
///
public abstract get text(): string;
protected abstract _setText(text: string): void;
protected abstract _createModelLine(text: string): IModelLine;
///
public applyEdits(edits: ILineEdit[]): number {
let deltaColumn = 0;
let resultText = this.text;
for (let i = 0, len = edits.length; i < len; i++) {
let edit = edits[i];
// console.log();
// console.log('=============================');
// console.log('EDIT #' + i + ' [ ' + edit.startColumn + ' -> ' + edit.endColumn + ' ] : <<<' + edit.text + '>>>');
// console.log('deltaColumn: ' + deltaColumn);
let startColumn = deltaColumn + edit.startColumn;
let endColumn = deltaColumn + edit.endColumn;
let deletingCnt = endColumn - startColumn;
let insertingCnt = edit.text.length;
// Perform the edit & update `deltaColumn`
resultText = resultText.substring(0, startColumn - 1) + edit.text + resultText.substring(endColumn - 1);
deltaColumn += insertingCnt - deletingCnt;
}
// Save the resulting text
this._setText(resultText);
return deltaColumn;
}
public split(splitColumn: number): IModelLine {
const myText = this.text.substring(0, splitColumn - 1);
const otherText = this.text.substring(splitColumn - 1);
this._setText(myText);
return this._createModelLine(otherText);
}
public append(other: IModelLine): void {
this._setText(this.text + other.text);
}
}
export class ModelLine extends AbstractModelLine implements IModelLine {
private _text: string;
public get text(): string { return this._text; }
constructor(text: string) {
super();
this._setText(text);
}
protected _createModelLine(text: string): IModelLine {
return new ModelLine(text);
}
public split(splitColumn: number): IModelLine {
return super.split(splitColumn);
}
public append(other: IModelLine): void {
super.append(other);
}
protected _setText(text: string): void {
this._text = text;
}
}
/**
* A model line that cannot store any tokenization state.
* It has no fields except the text.
*/
export class MinimalModelLine extends AbstractModelLine implements IModelLine {
private _text: string;
public get text(): string { return this._text; }
constructor(text: string) {
super();
this._setText(text);
}
protected _createModelLine(text: string): IModelLine {
return new MinimalModelLine(text);
}
public split(splitColumn: number): IModelLine {
return super.split(splitColumn);
}
public append(other: IModelLine): void {
super.append(other);
}
protected _setText(text: string): void {
this._text = text;
}
}
function getDefaultMetadata(topLevelLanguageId: LanguageId): number {
return (
(topLevelLanguageId << MetadataConsts.LANGUAGEID_OFFSET)
......
......@@ -500,7 +500,7 @@ export class TextBuffer {
}
// this._invalidateLine(currentLineNumber - 1); //TODO@TextBuffer
this._lines[currentLineNumber - 1] = applyLineEdits2(
this._lines[currentLineNumber - 1] = applyLineEdits(
this._lines[currentLineNumber - 1],
lineEditsQueue.slice(currentLineNumberStart, i)
);
......@@ -514,7 +514,7 @@ export class TextBuffer {
}
// this._invalidateLine(currentLineNumber - 1); //TODO@TextBuffer
this._lines[currentLineNumber - 1] = applyLineEdits2(
this._lines[currentLineNumber - 1] = applyLineEdits(
this._lines[currentLineNumber - 1],
lineEditsQueue.slice(currentLineNumberStart, lineEditsQueue.length)
);
......@@ -570,7 +570,7 @@ export class TextBuffer {
const spliceStartLineNumber = startLineNumber + editingLinesCnt;
const [t1, t2] = split(this._lines[endLineNumber - 1], endColumn);
const [t1, t2] = splitLine(this._lines[endLineNumber - 1], endColumn);
this._lines[endLineNumber - 1] = t1;
const endLineRemains = t2;
// this._invalidateLine(spliceStartLineNumber - 1); //TODO@TextBuffer
......@@ -606,7 +606,7 @@ export class TextBuffer {
}
// Split last line
const [t1, t2] = split(this._lines[spliceLineNumber - 1], spliceColumn);
const [t1, t2] = splitLine(this._lines[spliceLineNumber - 1], spliceColumn);
this._lines[spliceLineNumber - 1] = t1;
const leftoverLine = t2;
this._lineStarts.changeValue(spliceLineNumber - 1, this._lines[spliceLineNumber - 1].length + this._EOL.length);
......@@ -718,7 +718,7 @@ export class TextBuffer {
//#endregion
}
function applyLineEdits2(text: string, edits: ILineEdit[]): string {
export function applyLineEdits(text: string, edits: ILineEdit[]): string {
let deltaColumn = 0;
let resultText = text;
......@@ -744,7 +744,7 @@ function applyLineEdits2(text: string, edits: ILineEdit[]): string {
return resultText;
}
function split(text: string, splitColumn: number): [string, string] {
export function splitLine(text: string, splitColumn: number): [string, string] {
const myText = text.substring(0, splitColumn - 1);
const otherText = text.substring(splitColumn - 1);
......
......@@ -10,7 +10,6 @@ import { Position, IPosition } from 'vs/editor/common/core/position';
import { Range, IRange } from 'vs/editor/common/core/range';
import { Selection } from 'vs/editor/common/core/selection';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { ModelLine, IModelLine, MinimalModelLine } from 'vs/editor/common/model/modelLine';
import { guessIndentation, IndentationGuesserTextBufferTarget, IndentationGuesserStringArrayTarget } from 'vs/editor/common/model/indentationGuesser';
import { EDITOR_MODEL_DEFAULTS } from 'vs/editor/common/config/editorOptions';
import { TextModelSearch, SearchParams } from 'vs/editor/common/model/textModelSearch';
......@@ -123,13 +122,6 @@ export class TextModel extends Disposable implements editorCommon.ITextModel {
this._isDisposing = false;
}
protected _createModelLine(text: string): IModelLine {
if (this._isTooLargeForTokenization) {
return new MinimalModelLine(text);
}
return new ModelLine(text);
}
protected _assertNotDisposed(): void {
if (this._isDisposed) {
throw new Error('Model is disposed!');
......
......@@ -6,13 +6,14 @@
import * as assert from 'assert';
import { LineTokens } from 'vs/editor/common/core/lineTokens';
import { ModelLine, ILineEdit, computeIndentLevel } from 'vs/editor/common/model/modelLine';
import { ILineEdit, computeIndentLevel } from 'vs/editor/common/model/modelLine';
import { LanguageIdentifier, MetadataConsts } from 'vs/editor/common/modes';
import { Range } from 'vs/editor/common/core/range';
import { ViewLineToken, ViewLineTokenFactory } from 'vs/editor/test/common/core/viewLineToken';
import { EditableTextModel } from 'vs/editor/common/model/editableTextModel';
import { TextModel } from 'vs/editor/common/model/textModel';
import { RawTextSource } from 'vs/editor/common/model/textSource';
import { applyLineEdits, splitLine } from 'vs/editor/common/model/textBuffer';
function assertLineTokens(__actual: LineTokens, _expected: TestToken[]): void {
let tmp = TestToken.toTokens(_expected);
......@@ -66,9 +67,8 @@ suite('ModelLine - getIndentLevel', () => {
suite('Editor Model - modelLine.applyEdits text', () => {
function testEdits(initial: string, edits: ILineEdit[], expected: string): void {
var line = new ModelLine(initial);
line.applyEdits(edits);
assert.equal(line.text, expected);
const actual = applyLineEdits(initial, edits);
assert.equal(actual, expected);
}
function editOp(startColumn: number, endColumn: number, text: string): ILineEdit {
......@@ -212,10 +212,9 @@ 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(initial);
var newLine = line.split(splitColumn);
assert.equal(line.text, expected1);
assert.equal(newLine.text, expected2);
const [actual1, actual2] = splitLine(initial, splitColumn);
assert.equal(actual1, expected1);
assert.equal(actual2, expected2);
}
test('split at the beginning', () => {
......@@ -246,40 +245,6 @@ 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(a);
var line2 = new ModelLine(b);
line1.append(line2);
assert.equal(line1.text, expected);
}
test('append at the beginning', () => {
testLineAppend(
'',
'qwerty',
'qwerty'
);
});
test('append at the end', () => {
testLineAppend(
'qwerty',
'',
'qwerty'
);
});
test('append in the middle', () => {
testLineAppend(
'qw',
'erty',
'qwerty'
);
});
});
class TestToken {
public readonly startOffset: number;
public readonly color: number;
......@@ -1418,11 +1383,8 @@ suite('ModelLinesTokens', () => {
suite('Editor Model - modelLine.applyEdits', () => {
function testLineEdit(initialText: string, edits: ILineEdit[], expectedText: string): void {
let line = new ModelLine(initialText);
line.applyEdits(edits);
assert.equal(line.text, expectedText, 'text');
const actual = applyLineEdits(initialText, edits);
assert.equal(actual, expectedText, 'text');
}
test('insertion: updates markers 1', () => {
......@@ -1773,12 +1735,10 @@ suite('Editor Model - modelLine.applyEdits', () => {
suite('Editor Model - modelLine.split', () => {
function testLineSplit(initialText: string, splitColumn: number, forceMoveMarkers: boolean, expectedText1: string, expectedText2: string): void {
let line = new ModelLine(initialText);
let otherLine = line.split(splitColumn);
const [l1, l2] = splitLine(initialText, splitColumn);
assert.equal(line.text, expectedText1, 'text');
assert.equal(otherLine.text, expectedText2, 'text');
assert.equal(l1, expectedText1, 'text');
assert.equal(l2, expectedText2, 'text');
}
test('split at the beginning', () => {
......@@ -1851,47 +1811,3 @@ suite('Editor Model - modelLine.split', () => {
);
});
});
suite('Editor Model - modelLine.append', () => {
function testLinePrependMarkers(aText: string, bText: string, expectedText: string): void {
let a = new ModelLine(aText);
let b = new ModelLine(bText);
a.append(b);
assert.equal(a.text, expectedText, 'text');
}
test('append to an empty', () => {
testLinePrependMarkers(
'abcd efgh',
'',
'abcd efgh',
);
});
test('append an empty', () => {
testLinePrependMarkers(
'',
'abcd efgh',
'abcd efgh',
);
});
test('append 1', () => {
testLinePrependMarkers(
'abcd',
' efgh',
'abcd efgh',
);
});
test('append 2', () => {
testLinePrependMarkers(
'abcd e',
'fgh',
'abcd efgh',
);
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册