1
>
/*---------------------------------------------------------------------------------------------
mirrorTextModel.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { splitLines } from '../../../base/common/strings.js';
7
>
import { URI } from '../../../base/common/uri.js';
8
>
import { Position } from '../core/position.js';
9
>
import { IRange } from '../core/range.js';
10
>
import { PrefixSumComputer } from './prefixSumComputer.js';
11
>
12
>
export interface IModelContentChange {
13
>
/**
14
>
* The old range that got replaced.
15
>
*/
16
>
readonly range: IRange;
17
>
/**
18
>
* The offset of the range that got replaced.
19
>
*/
20
>
readonly rangeOffset: number;
21
>
/**
22
>
* The length of the range that got replaced.
23
>
*/
24
>
readonly rangeLength: number;
25
>
/**
26
>
* The new text for the range.
27
>
*/
28
>
readonly text: string;
29
>
}
30
>
31
>
export interface IModelChangedEvent {
32
>
/**
33
>
* The actual changes.
34
>
*/
35
>
readonly changes: IModelContentChange[];
36
>
/**
37
>
* The (new) end-of-line character.
38
>
*/
39
>
readonly eol: string;
40
>
/**
41
>
* The new version id the model has transitioned to.
42
>
*/
43
>
readonly versionId: number;
44
>
/**
45
>
* Flag that indicates that this event was generated while undoing.
46
>
*/
47
>
readonly isUndoing: boolean;
48
>
/**
49
>
* Flag that indicates that this event was generated while redoing.
50
>
*/
51
>
readonly isRedoing: boolean;
52
>
}
53
>
54
>
export interface IMirrorTextModel {
55
>
readonly version: number;
56
>
}
57
>
58
>
export class MirrorTextModel implements IMirrorTextModel {
59
>
60
>
protected _uri: URI;
61
>
protected _lines: string[];
62
>
protected _eol: string;
63
>
protected _versionId: number;
64
>
protected _lineStarts: PrefixSumComputer | null;
65
>
private _cachedTextValue: string | null;
66
>
67
>
constructor(uri: URI, lines: string[], eol: string, versionId: number) {
68
this._uri = uri;
69
this._lines = lines;