@@ -7,7 +7,7 @@ import { Emitter, Event } from 'vs/base/common/event';
77import { Disposable , IDisposable } from 'vs/base/common/lifecycle' ;
88import { URI } from 'vs/base/common/uri' ;
99import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel' ;
10- import { INotebookTextModel , NotebookCellOutputsSplice , NotebookCellTextModelSplice , NotebookDocumentMetadata , NotebookCellMetadata , ICellEditOperation , CellEditType , CellUri , ICellInsertEdit , NotebookCellsChangedEvent , CellKind , IProcessedOutput , notebookDocumentMetadataDefaults , diff , ICellDeleteEdit , NotebookCellsChangeType , ICellDto2 } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
10+ import { INotebookTextModel , NotebookCellOutputsSplice , NotebookCellTextModelSplice , NotebookDocumentMetadata , NotebookCellMetadata , ICellEditOperation , CellEditType , CellUri , ICellInsertEdit , NotebookCellsChangedEvent , CellKind , IProcessedOutput , notebookDocumentMetadataDefaults , diff , ICellDeleteEdit , NotebookCellsChangeType , ICellDto2 , IMainCellDto } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
1111import { ITextSnapshot } from 'vs/editor/common/model' ;
1212
1313function compareRangesUsingEnds ( a : [ number , number ] , b : [ number , number ] ) : number {
@@ -71,7 +71,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
7171 private readonly _onDidChangeCells = new Emitter < NotebookCellTextModelSplice [ ] > ( ) ;
7272 get onDidChangeCells ( ) : Event < NotebookCellTextModelSplice [ ] > { return this . _onDidChangeCells . event ; }
7373 private _onDidModelChangeProxy = new Emitter < NotebookCellsChangedEvent > ( ) ;
74- get onDidModelChange ( ) : Event < NotebookCellsChangedEvent > { return this . _onDidModelChangeProxy . event ; }
74+ get onDidModelChangeProxy ( ) : Event < NotebookCellsChangedEvent > { return this . _onDidModelChangeProxy . event ; }
7575 private _onDidSelectionChangeProxy = new Emitter < number [ ] | null > ( ) ;
7676 get onDidSelectionChange ( ) : Event < number [ ] | null > { return this . _onDidSelectionChangeProxy . event ; }
7777 private _onDidChangeContent = new Emitter < void > ( ) ;
@@ -182,10 +182,10 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
182182 const cellUri = CellUri . generate ( this . uri , cellHandle ) ;
183183 return new NotebookCellTextModel ( cellUri , cellHandle , cell . source , cell . language , cell . cellKind , cell . outputs || [ ] , cell . metadata ) ;
184184 } ) ;
185- this . insertNewCell ( insertEdit . index , mainCells ) ;
185+ this . insertNewCell ( insertEdit . index , mainCells , false ) ;
186186 break ;
187187 case CellEditType . Delete :
188- this . removeCell ( operations [ i ] . index , operations [ i ] . end - operations [ i ] . start ) ;
188+ this . removeCell ( operations [ i ] . index , operations [ i ] . end - operations [ i ] . start , false ) ;
189189 break ;
190190 }
191191 }
@@ -196,10 +196,19 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
196196 return [ diff . start , diff . deleteCount , diff . toInsert ] as [ number , number , NotebookCellTextModel [ ] ] ;
197197 } ) ;
198198
199- // this._onDidModelChangeProxy.fire({kind: NotebookCellsChangeType.ModelChange,
200- // versionId: this._versionId, change: diffs
201- // }
202- // );
199+ this . _onDidModelChangeProxy . fire ( {
200+ kind : NotebookCellsChangeType . ModelChange ,
201+ versionId : this . _versionId ,
202+ changes : diffs . map ( diff => [ diff [ 0 ] , diff [ 1 ] , diff [ 2 ] . map ( cell => ( {
203+ handle : cell . handle ,
204+ uri : cell . uri ,
205+ source : cell . textBuffer . getLinesContent ( ) ,
206+ language : cell . language ,
207+ cellKind : cell . cellKind ,
208+ outputs : cell . outputs ,
209+ metadata : cell . metadata
210+ } ) ) ] as [ number , number , IMainCellDto [ ] ] )
211+ } ) ;
203212
204213 this . _onDidChangeCells . fire ( diffs ) ;
205214 return true ;
@@ -260,8 +269,8 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
260269
261270 this . _onDidModelChangeProxy . fire ( {
262271 kind : NotebookCellsChangeType . ModelChange ,
263- versionId : this . _versionId , change :
264- [
272+ versionId : this . _versionId , changes :
273+ [ [
265274 0 ,
266275 0 ,
267276 [ {
@@ -273,13 +282,13 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
273282 outputs : cell . outputs ,
274283 metadata : cell . metadata
275284 } ]
276- ]
285+ ] ]
277286 } ) ;
278287
279288 return ;
280289 }
281290
282- insertNewCell ( index : number , cells : NotebookCellTextModel [ ] ) : void {
291+ insertNewCell ( index : number , cells : NotebookCellTextModel [ ] , emitToExtHost : boolean = true ) : void {
283292 this . _isUntitled = false ;
284293
285294 for ( let i = 0 ; i < cells . length ; i ++ ) {
@@ -294,28 +303,31 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
294303 this . cells . splice ( index , 0 , ...cells ) ;
295304 this . _onDidChangeContent . fire ( ) ;
296305 this . _increaseVersionId ( ) ;
297- this . _onDidModelChangeProxy . fire ( {
298- kind : NotebookCellsChangeType . ModelChange ,
299- versionId : this . _versionId , change :
300- [
301- index ,
302- 0 ,
303- cells . map ( cell => ( {
304- handle : cell . handle ,
305- uri : cell . uri ,
306- source : cell . textBuffer . getLinesContent ( ) ,
307- language : cell . language ,
308- cellKind : cell . cellKind ,
309- outputs : cell . outputs ,
310- metadata : cell . metadata
311- } ) )
312- ]
313- } ) ;
306+
307+ if ( emitToExtHost ) {
308+ this . _onDidModelChangeProxy . fire ( {
309+ kind : NotebookCellsChangeType . ModelChange ,
310+ versionId : this . _versionId , changes :
311+ [ [
312+ index ,
313+ 0 ,
314+ cells . map ( cell => ( {
315+ handle : cell . handle ,
316+ uri : cell . uri ,
317+ source : cell . textBuffer . getLinesContent ( ) ,
318+ language : cell . language ,
319+ cellKind : cell . cellKind ,
320+ outputs : cell . outputs ,
321+ metadata : cell . metadata
322+ } ) )
323+ ] ]
324+ } ) ;
325+ }
314326
315327 return ;
316328 }
317329
318- removeCell ( index : number , count : number ) {
330+ removeCell ( index : number , count : number , emitToExtHost : boolean = true ) {
319331 this . _isUntitled = false ;
320332
321333 for ( let i = index ; i < index + count ; i ++ ) {
@@ -327,18 +339,23 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
327339 this . _onDidChangeContent . fire ( ) ;
328340
329341 this . _increaseVersionId ( ) ;
330- this . _onDidModelChangeProxy . fire ( { kind : NotebookCellsChangeType . ModelChange , versionId : this . _versionId , change : [ index , count , [ ] ] } ) ;
342+ if ( emitToExtHost ) {
343+ this . _onDidModelChangeProxy . fire ( { kind : NotebookCellsChangeType . ModelChange , versionId : this . _versionId , changes : [ [ index , count , [ ] ] ] } ) ;
344+ }
331345 }
332346
333- moveCellToIdx ( index : number , newIdx : number ) {
347+ moveCellToIdx ( index : number , newIdx : number , emitToExtHost : boolean = true ) {
334348 this . assertIndex ( index ) ;
335349 this . assertIndex ( newIdx ) ;
336350
337351 const cells = this . cells . splice ( index , 1 ) ;
338352 this . cells . splice ( newIdx , 0 , ...cells ) ;
339353
340354 this . _increaseVersionId ( ) ;
341- this . _onDidModelChangeProxy . fire ( { kind : NotebookCellsChangeType . Move , versionId : this . _versionId , index, newIdx } ) ;
355+
356+ if ( emitToExtHost ) {
357+ this . _onDidModelChangeProxy . fire ( { kind : NotebookCellsChangeType . Move , versionId : this . _versionId , index, newIdx } ) ;
358+ }
342359 }
343360
344361 assertIndex ( index : number ) {
0 commit comments