@@ -111,19 +111,14 @@ class DelayedEmitter {
111
111
112
112
}
113
113
114
- emit ( data : {
115
- contentChange : { value : NotebookTextModelChangedEvent } | undefined ,
116
- } ) {
114
+ emit ( data : NotebookTextModelChangedEvent ) {
117
115
this . _increaseVersion ( ) ;
118
-
119
- if ( data . contentChange ) {
120
- this . _onDidChangeContent . fire (
121
- {
122
- ...data . contentChange . value ,
123
- versionId : this . _textModel . versionId
124
- }
125
- ) ;
126
- }
116
+ this . _onDidChangeContent . fire (
117
+ {
118
+ ...data ,
119
+ versionId : this . _textModel . versionId
120
+ }
121
+ ) ;
127
122
}
128
123
}
129
124
@@ -217,11 +212,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
217
212
for ( let i = 0 ; i < mainCells . length ; i ++ ) {
218
213
this . _mapping . set ( mainCells [ i ] . handle , mainCells [ i ] ) ;
219
214
const dirtyStateListener = mainCells [ i ] . onDidChangeContent ( ( ) => {
220
- this . _eventEmitter . emit ( {
221
- contentChange : {
222
- value : { kind : NotebookCellsChangeType . ChangeCellContent , versionId : this . versionId , synchronous : true , transient : false }
223
- }
224
- } ) ;
215
+ this . _eventEmitter . emit ( { kind : NotebookCellsChangeType . ChangeCellContent , versionId : this . versionId , synchronous : true , transient : false } ) ;
225
216
} ) ;
226
217
227
218
this . _cellListeners . set ( mainCells [ i ] . handle , dirtyStateListener ) ;
@@ -312,9 +303,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
312
303
this . _modelService
313
304
) ;
314
305
const dirtyStateListener = cell . onDidChangeContent ( ( ) => {
315
- this . _eventEmitter . emit ( {
316
- contentChange : { value : { kind : NotebookCellsChangeType . ChangeCellContent , versionId : this . versionId , synchronous : true , transient : false } }
317
- } ) ;
306
+ this . _eventEmitter . emit ( { kind : NotebookCellsChangeType . ChangeCellContent , versionId : this . versionId , synchronous : true , transient : false } ) ;
318
307
} ) ;
319
308
this . _cellListeners . set ( cell . handle , dirtyStateListener ) ;
320
309
this . _mapping . set ( cell . handle , cell ) ;
@@ -342,15 +331,11 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
342
331
343
332
// should be deferred
344
333
this . _eventEmitter . emit ( {
345
- contentChange : {
346
- value : {
347
- kind : NotebookCellsChangeType . ModelChange ,
348
- versionId : this . _versionId ,
349
- changes : diffs ,
350
- synchronous,
351
- transient : false
352
- }
353
- }
334
+ kind : NotebookCellsChangeType . ModelChange ,
335
+ versionId : this . _versionId ,
336
+ changes : diffs ,
337
+ synchronous,
338
+ transient : false
354
339
} ) ;
355
340
}
356
341
@@ -368,27 +353,19 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
368
353
} ) ;
369
354
370
355
this . _eventEmitter . emit ( {
371
- contentChange : {
372
- value : {
373
- kind : NotebookCellsChangeType . Unknown ,
374
- transient : false ,
375
- synchronous : true ,
376
- versionId : this . _versionId ,
377
- }
378
- }
356
+ kind : NotebookCellsChangeType . Unknown ,
357
+ transient : false ,
358
+ synchronous : true ,
359
+ versionId : this . _versionId ,
379
360
} ) ;
380
361
}
381
362
382
363
handleUnknownChange ( ) {
383
364
this . _eventEmitter . emit ( {
384
- contentChange : {
385
- value : {
386
- kind : NotebookCellsChangeType . Unknown ,
387
- transient : false ,
388
- synchronous : true ,
389
- versionId : this . _versionId ,
390
- }
391
- }
365
+ kind : NotebookCellsChangeType . Unknown ,
366
+ transient : false ,
367
+ synchronous : true ,
368
+ versionId : this . _versionId ,
392
369
} ) ;
393
370
}
394
371
@@ -413,39 +390,31 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
413
390
414
391
updateNotebookMetadata ( metadata : NotebookDocumentMetadata ) {
415
392
this . metadata = metadata ;
416
- this . _eventEmitter . emit ( {
417
- contentChange : { value : { kind : NotebookCellsChangeType . ChangeDocumentMetadata , versionId : this . versionId , metadata : this . metadata , synchronous : true , transient : false } }
418
- } ) ;
393
+ this . _eventEmitter . emit ( { kind : NotebookCellsChangeType . ChangeDocumentMetadata , versionId : this . versionId , metadata : this . metadata , synchronous : true , transient : false } ) ;
419
394
}
420
395
421
396
private _insertNewCell ( index : number , cells : NotebookCellTextModel [ ] , synchronous : boolean , endSelections ?: number [ ] ) : void {
422
397
for ( let i = 0 ; i < cells . length ; i ++ ) {
423
398
this . _mapping . set ( cells [ i ] . handle , cells [ i ] ) ;
424
399
const dirtyStateListener = cells [ i ] . onDidChangeContent ( ( ) => {
425
- this . _eventEmitter . emit ( {
426
- contentChange : { value : { kind : NotebookCellsChangeType . ChangeCellContent , versionId : this . versionId , synchronous : true , transient : false } }
427
- } ) ;
400
+ this . _eventEmitter . emit ( { kind : NotebookCellsChangeType . ChangeCellContent , versionId : this . versionId , synchronous : true , transient : false } ) ;
428
401
} ) ;
429
402
430
403
this . _cellListeners . set ( cells [ i ] . handle , dirtyStateListener ) ;
431
404
}
432
405
433
406
this . _cells . splice ( index , 0 , ...cells ) ;
434
407
this . _eventEmitter . emit ( {
435
- contentChange : {
436
- value : {
437
- kind : NotebookCellsChangeType . ModelChange ,
438
- versionId : this . _versionId , changes :
439
- [ [
440
- index ,
441
- 0 ,
442
- cells
443
- ] ] ,
444
- synchronous,
445
- endSelections : endSelections ,
446
- transient : false
447
- }
448
- }
408
+ kind : NotebookCellsChangeType . ModelChange ,
409
+ versionId : this . _versionId , changes :
410
+ [ [
411
+ index ,
412
+ 0 ,
413
+ cells
414
+ ] ] ,
415
+ synchronous,
416
+ endSelections : endSelections ,
417
+ transient : false
449
418
} ) ;
450
419
451
420
return ;
@@ -458,9 +427,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
458
427
this . _cellListeners . delete ( cell . handle ) ;
459
428
}
460
429
this . _cells . splice ( index , count ) ;
461
- this . _eventEmitter . emit ( {
462
- contentChange : { value : { kind : NotebookCellsChangeType . ModelChange , versionId : this . _versionId , changes : [ [ index , count , [ ] ] ] , synchronous, endSelections, transient : false } }
463
- } ) ;
430
+ this . _eventEmitter . emit ( { kind : NotebookCellsChangeType . ModelChange , versionId : this . _versionId , changes : [ [ index , count , [ ] ] ] , synchronous, endSelections, transient : false } ) ;
464
431
}
465
432
466
433
private _isCellMetadataChanged ( a : NotebookCellMetadata , b : NotebookCellMetadata ) {
@@ -506,21 +473,15 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
506
473
cell . metadata = metadata ;
507
474
}
508
475
509
- this . _eventEmitter . emit ( {
510
- contentChange : {
511
- value : { kind : NotebookCellsChangeType . ChangeCellMetadata , versionId : this . _versionId , index : this . _cells . indexOf ( cell ) , metadata : cell . metadata , synchronous : true , transient : ! triggerDirtyChange }
512
- }
513
- } ) ;
476
+ this . _eventEmitter . emit ( { kind : NotebookCellsChangeType . ChangeCellMetadata , versionId : this . _versionId , index : this . _cells . indexOf ( cell ) , metadata : cell . metadata , synchronous : true , transient : ! triggerDirtyChange } ) ;
514
477
}
515
478
516
479
private _changeCellLanguage ( handle : number , languageId : string ) {
517
480
const cell = this . _mapping . get ( handle ) ;
518
481
if ( cell && cell . language !== languageId ) {
519
482
cell . language = languageId ;
520
483
521
- this . _eventEmitter . emit ( {
522
- contentChange : { value : { kind : NotebookCellsChangeType . ChangeLanguage , versionId : this . _versionId , index : this . _cells . indexOf ( cell ) , language : languageId , synchronous : true , transient : false } }
523
- } ) ;
484
+ this . _eventEmitter . emit ( { kind : NotebookCellsChangeType . ChangeLanguage , versionId : this . _versionId , index : this . _cells . indexOf ( cell ) , language : languageId , synchronous : true , transient : false } ) ;
524
485
}
525
486
}
526
487
@@ -531,19 +492,14 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
531
492
cell . spliceNotebookCellOutputs ( splices ) ;
532
493
533
494
this . _eventEmitter . emit ( {
534
- contentChange : {
535
- value : {
536
- kind : NotebookCellsChangeType . Output ,
537
- versionId : this . versionId ,
538
- index : this . _cells . indexOf ( cell ) ,
539
- outputs : cell . outputs ?? [ ] ,
540
- transient : this . transientOptions . transientOutputs ,
541
- synchronous : true
542
- }
543
- }
495
+ kind : NotebookCellsChangeType . Output ,
496
+ versionId : this . versionId ,
497
+ index : this . _cells . indexOf ( cell ) ,
498
+ outputs : cell . outputs ?? [ ] ,
499
+ transient : this . transientOptions . transientOutputs ,
500
+ synchronous : true
544
501
} ) ;
545
502
}
546
-
547
503
}
548
504
549
505
private _assertIndex ( index : number ) {
@@ -589,13 +545,9 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
589
545
this . _assertIndex ( index ) ;
590
546
this . _assertIndex ( newIdx ) ;
591
547
592
- {
593
- const cells = this . _cells . splice ( index , length ) ;
594
- this . _cells . splice ( newIdx , 0 , ...cells ) ;
595
- this . _eventEmitter . emit ( {
596
- contentChange : { value : { kind : NotebookCellsChangeType . Move , versionId : this . _versionId , index, length, newIdx, cells, synchronous, endSelections, transient : false } }
597
- } ) ;
598
- }
548
+ const cells = this . _cells . splice ( index , length ) ;
549
+ this . _cells . splice ( newIdx , 0 , ...cells ) ;
550
+ this . _eventEmitter . emit ( { kind : NotebookCellsChangeType . Move , versionId : this . _versionId , index, length, newIdx, cells, synchronous, endSelections, transient : false } ) ;
599
551
600
552
return true ;
601
553
}
0 commit comments