@@ -19,7 +19,7 @@ export class CSharpProjectedDocument implements IProjectedDocument {
19
19
private resolveProvisionalEditAt : number | undefined ;
20
20
private ProvisionalDotPosition : Position | undefined ;
21
21
private hostDocumentVersion : number | null = null ;
22
- private edits : ServerTextChange [ ] | null = null ;
22
+ private updates : Update [ ] | null = null ;
23
23
24
24
public constructor ( public readonly uri : vscode . Uri ) {
25
25
this . path = getUriPath ( uri ) ;
@@ -38,38 +38,45 @@ export class CSharpProjectedDocument implements IProjectedDocument {
38
38
}
39
39
40
40
public update ( edits : ServerTextChange [ ] , hostDocumentVersion : number ) {
41
+ this . removeProvisionalDot ( ) ;
42
+
41
43
// 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
+ }
46
48
47
- this . removeProvisionalDot ( ) ;
49
+ this . updates = null ;
50
+ }
48
51
49
52
this . hostDocumentVersion = hostDocumentVersion ;
50
-
51
53
this . updateContent ( edits ) ;
52
54
}
53
55
54
56
public storeEdits ( edits : ServerTextChange [ ] , hostDocumentVersion : number ) {
55
57
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 ) ) ;
58
60
} else {
59
- this . edits = edits ;
61
+ this . updates = [ new Update ( edits ) ] ;
60
62
}
61
63
}
62
64
63
65
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
+ }
65
75
66
- // Make sure the internal representation of the content is updated
67
- if ( edits ) {
68
- this . updateContent ( edits ) ;
76
+ return changes ;
69
77
}
70
78
71
- this . edits = null ;
72
- return edits ;
79
+ return null ;
73
80
}
74
81
75
82
public getContent ( ) {
@@ -158,8 +165,8 @@ export class CSharpProjectedDocument implements IProjectedDocument {
158
165
}
159
166
160
167
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 ) ;
163
170
content = `${ before } ${ newText } ${ after } ` ;
164
171
165
172
return content ;
@@ -183,3 +190,7 @@ export class CSharpProjectedDocument implements IProjectedDocument {
183
190
this . setContent ( content ) ;
184
191
}
185
192
}
193
+
194
+ class Update {
195
+ constructor ( public readonly changes : ServerTextChange [ ] ) { }
196
+ }
0 commit comments