@@ -15,7 +15,9 @@ import { Selection } from 'vs/editor/common/core/selection';
15
15
import { LineRangeMapping } from 'vs/editor/common/diff/linesDiffComputer' ;
16
16
import { IEditorDecorationsCollection } from 'vs/editor/common/editorCommon' ;
17
17
import { ICursorStateComputer , IModelDecorationOptions , IModelDeltaDecoration , IValidEditOperation } from 'vs/editor/common/model' ;
18
+ import { createTextBufferFactoryFromSnapshot } from 'vs/editor/common/model/textModel' ;
18
19
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorker' ;
20
+ import { IModelService } from 'vs/editor/common/services/model' ;
19
21
import { localize } from 'vs/nls' ;
20
22
import { IContextKey , IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
21
23
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
@@ -206,7 +208,8 @@ export class LiveStrategy extends EditModeStrategy {
206
208
@IContextKeyService contextKeyService : IContextKeyService ,
207
209
@IStorageService protected _storageService : IStorageService ,
208
210
@IBulkEditService protected readonly _bulkEditService : IBulkEditService ,
209
- @IEditorWorkerService protected readonly _editorWorkerService : IEditorWorkerService
211
+ @IEditorWorkerService protected readonly _editorWorkerService : IEditorWorkerService ,
212
+ @IModelService private readonly _modelService : IModelService
210
213
) {
211
214
super ( ) ;
212
215
this . _inlineDiffDecorations = new InlineDiffDecorations ( this . _editor , this . _inlineDiffEnabled ) ;
@@ -257,11 +260,13 @@ export class LiveStrategy extends EditModeStrategy {
257
260
}
258
261
259
262
async cancel ( ) {
260
- const { textModelN : modelN , textModel0 : model0 } = this . _session ;
261
- if ( modelN . isDisposed ( ) || model0 . isDisposed ( ) ) {
263
+ const { textModelN : modelN , textModel0 : model0 , lastSnapshot } = this . _session ;
264
+ if ( modelN . isDisposed ( ) || ( model0 . isDisposed ( ) && ! lastSnapshot ) ) {
262
265
return ;
263
266
}
264
- const edits = await this . _editorWorkerService . computeMoreMinimalEdits ( modelN . uri , [ { range : modelN . getFullModelRange ( ) , text : model0 . getValue ( ) } ] ) ;
267
+
268
+ const initialTextModel = lastSnapshot ? this . _modelService . createModel ( createTextBufferFactoryFromSnapshot ( lastSnapshot ) , null ) : model0 ;
269
+ const edits = await this . _editorWorkerService . computeMoreMinimalEdits ( modelN . uri , [ { range : modelN . getFullModelRange ( ) , text : initialTextModel . getValue ( ) } ] ) ;
265
270
if ( edits ) {
266
271
const operations = edits . map ( e => EditOperation . replace ( Range . lift ( e . range ) , e . text ) ) ;
267
272
modelN . pushEditOperations ( null , operations , ( ) => null ) ;
@@ -326,8 +331,9 @@ export class LivePreviewStrategy extends LiveStrategy {
326
331
@IBulkEditService bulkEditService : IBulkEditService ,
327
332
@IEditorWorkerService editorWorkerService : IEditorWorkerService ,
328
333
@IInstantiationService instaService : IInstantiationService ,
334
+ @IModelService modelService : IModelService
329
335
) {
330
- super ( session , editor , widget , contextKeyService , storageService , bulkEditService , editorWorkerService ) ;
336
+ super ( session , editor , widget , contextKeyService , storageService , bulkEditService , editorWorkerService , modelService ) ;
331
337
332
338
this . _diffZone = instaService . createInstance ( InteractiveEditorLivePreviewWidget , editor , session . textModel0 ) ;
333
339
this . _previewZone = instaService . createInstance ( InteractiveEditorFileCreatePreviewWidget , editor ) ;
0 commit comments