Skip to content

Commit 212e710

Browse files
author
Andrew Hall
committed
Encapsulate each set of changes in an Update class
1 parent 2f4b51c commit 212e710

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

src/razor/src/csharp/csharpProjectedDocument.ts

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class CSharpProjectedDocument implements IProjectedDocument {
1919
private resolveProvisionalEditAt: number | undefined;
2020
private ProvisionalDotPosition: Position | undefined;
2121
private hostDocumentVersion: number | null = null;
22-
private edits: ServerTextChange[] | null = null;
22+
private updates: Update[] | null = null;
2323

2424
public constructor(public readonly uri: vscode.Uri) {
2525
this.path = getUriPath(uri);
@@ -38,38 +38,45 @@ export class CSharpProjectedDocument implements IProjectedDocument {
3838
}
3939

4040
public update(edits: ServerTextChange[], hostDocumentVersion: number) {
41+
this.removeProvisionalDot();
42+
4143
// Apply any stored edits if needed
42-
if (this.edits) {
43-
edits = this.edits.concat(edits);
44-
this.edits = null;
45-
}
44+
if (this.updates) {
45+
for (const update of this.updates) {
46+
this.updateContent(update.changes);
47+
}
4648

47-
this.removeProvisionalDot();
49+
this.updates = null;
50+
}
4851

4952
this.hostDocumentVersion = hostDocumentVersion;
50-
5153
this.updateContent(edits);
5254
}
5355

5456
public storeEdits(edits: ServerTextChange[], hostDocumentVersion: number) {
5557
this.hostDocumentVersion = hostDocumentVersion;
56-
if (this.edits) {
57-
this.edits = this.edits.concat(edits);
58+
if (this.updates) {
59+
this.updates = this.updates.concat(new Update(edits));
5860
} else {
59-
this.edits = edits;
61+
this.updates = [new Update(edits)];
6062
}
6163
}
6264

6365
public getAndApplyEdits() {
64-
const edits = this.edits;
66+
const updates = this.updates;
67+
this.updates = null;
68+
69+
if (updates) {
70+
let changes: ServerTextChange[] = [];
71+
for (const update of updates) {
72+
this.updateContent(update.changes);
73+
changes = changes.concat(update.changes);
74+
}
6575

66-
// Make sure the internal representation of the content is updated
67-
if (edits) {
68-
this.updateContent(edits);
76+
return changes;
6977
}
7078

71-
this.edits = null;
72-
return edits;
79+
return null;
7380
}
7481

7582
public getContent() {
@@ -158,8 +165,8 @@ export class CSharpProjectedDocument implements IProjectedDocument {
158165
}
159166

160167
private getEditedContent(newText: string, start: number, end: number, content: string) {
161-
const before = content.substr(0, start);
162-
const after = content.substr(end);
168+
const before = content.substring(0, start);
169+
const after = content.substring(end);
163170
content = `${before}${newText}${after}`;
164171

165172
return content;
@@ -183,3 +190,7 @@ export class CSharpProjectedDocument implements IProjectedDocument {
183190
this.setContent(content);
184191
}
185192
}
193+
194+
class Update {
195+
constructor(public readonly changes: ServerTextChange[]) {}
196+
}

0 commit comments

Comments
 (0)