-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTextChanges.ts
89 lines (70 loc) · 1.56 KB
/
TextChanges.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
export class Offset {
constructor(public readonly offset: number) {}
}
export class Position {
constructor(public readonly line: number, public readonly column: number) {}
}
export class Range {}
export class Change {
constructor(
public readonly range: Range,
public readonly newText: string
) {}
}
export class Edit {
constructor(public readonly changes: ReadonlyArray<Change>) {}
}
export function applyEdit(src: string, edit: Edit): string {}
interface Buffer {
length: number;
applyChange(change: Change): void;
}
class TextBuffer implements Buffer {
public _text: string;
constructor(text: string) {
this._text = text;
}
public get text(): string {
return this._text;
}
public get length(): number {
return this._text.length;
}
public applyChange(change: Change): void {
this._text = applyEdit(this._text, new Edit([change]));
}
}
class Projection {
private _range: Range;
private _removed: boolean;
public get range(): Range {
return this._range;
}
public get removed(): boolean {
return this._removed;
}
constructor(
range: Range,
removed: boolean,
public readonly extendStart: boolean,
public readonly extendEnd: boolean,
public readonly buffer: Buffer | null
) {
this._range = range;
this._removed = removed;
}
public processEdit(edit: Edit): void {}
}
// (_)
// 12[](x)3
// (_)
// => 12x3
// (_]
// 12[](x)3
// (__]
// => 12x3
export function applyEditGetReverse(
src: string,
edit: Edit
): { result: string; reverseEdit: Edit } {}
export function combineEdits(edit1: Edit, edit2: Edit): Edit {}