diff --git a/src/vs/editor/common/model/mirrorTextModel.ts b/src/vs/editor/common/model/mirrorTextModel.ts index 25b3d150ce07834c88d269bd2ff8a8775a4bb69a..6a1272552b0e1e09586251fb3f42b848a912cf80 100644 --- a/src/vs/editor/common/model/mirrorTextModel.ts +++ b/src/vs/editor/common/model/mirrorTextModel.ts @@ -31,6 +31,7 @@ export class MirrorTextModel { protected _eol: string; protected _versionId: number; protected _lineStarts: PrefixSumComputer | null; + private _cachedTextValue: string | null; constructor(uri: URI, lines: string[], eol: string, versionId: number) { this._uri = uri; @@ -38,6 +39,7 @@ export class MirrorTextModel { this._eol = eol; this._versionId = versionId; this._lineStarts = null; + this._cachedTextValue = null; } dispose(): void { @@ -49,7 +51,10 @@ export class MirrorTextModel { } getText(): string { - return this._lines.join(this._eol); + if (this._cachedTextValue === null) { + this._cachedTextValue = this._lines.join(this._eol); + } + return this._cachedTextValue; } onEvents(e: IModelChangedEvent): void { @@ -66,6 +71,7 @@ export class MirrorTextModel { } this._versionId = e.versionId; + this._cachedTextValue = null; } protected _ensureLineStarts(): void {