@@ -8,7 +8,7 @@ import { Emitter, Event, PauseableEmitter } from 'vs/base/common/event';
8
8
import { Disposable , dispose , IDisposable } from 'vs/base/common/lifecycle' ;
9
9
import { URI } from 'vs/base/common/uri' ;
10
10
import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel' ;
11
- import { INotebookTextModel , NotebookCellOutputsSplice , NotebookDocumentMetadata , NotebookCellMetadata , ICellEditOperation , CellEditType , CellUri , diff , NotebookCellsChangeType , ICellDto2 , TransientOptions , NotebookTextModelChangedEvent , IOutputDto , ICellOutput , IOutputItemDto , ISelectionState , NullablePartialNotebookCellMetadata , NotebookCellInternalMetadata , NullablePartialNotebookCellInternalMetadata , NotebookTextModelWillAddRemoveEvent , NotebookCellTextModelSplice , ICell } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
11
+ import { INotebookTextModel , NotebookCellOutputsSplice , NotebookDocumentMetadata , NotebookCellMetadata , ICellEditOperation , CellEditType , CellUri , diff , NotebookCellsChangeType , ICellDto2 , TransientOptions , NotebookTextModelChangedEvent , IOutputDto , ICellOutput , IOutputItemDto , ISelectionState , NullablePartialNotebookCellMetadata , NotebookCellInternalMetadata , NullablePartialNotebookCellInternalMetadata , NotebookTextModelWillAddRemoveEvent , NotebookCellTextModelSplice , ICell , NotebookCellCollapseState , NotebookCellDefaultCollapseConfig , CellKind } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
12
12
import { IUndoRedoService , UndoRedoElementType , IUndoRedoElement , IResourceUndoRedoElement , UndoRedoGroup , IWorkspaceUndoRedoElement } from 'vs/platform/undoRedo/common/undoRedo' ;
13
13
import { MoveCellEdit , SpliceCellsEdit , CellMetadataEdit } from 'vs/workbench/contrib/notebook/common/model/cellEdit' ;
14
14
import { ISequence , LcsDiff } from 'vs/base/common/diff/diff' ;
@@ -168,6 +168,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
168
168
private _cellhandlePool : number = 0 ;
169
169
private readonly _cellListeners : Map < number , IDisposable > = new Map ( ) ;
170
170
private _cells : NotebookCellTextModel [ ] = [ ] ;
171
+ private _defaultCollapseConfig : NotebookCellDefaultCollapseConfig | undefined ;
171
172
172
173
metadata : NotebookDocumentMetadata = { } ;
173
174
transientOptions : TransientOptions = { transientCellMetadata : { } , transientDocumentMetadata : { } , transientOutputs : false } ;
@@ -269,6 +270,10 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
269
270
) ;
270
271
}
271
272
273
+ setCellCollapseDefault ( collapseConfig : NotebookCellDefaultCollapseConfig | undefined ) {
274
+ this . _defaultCollapseConfig = collapseConfig ;
275
+ }
276
+
272
277
_initialize ( cells : ICellDto2 [ ] , triggerDirty ?: boolean ) {
273
278
this . _cells = [ ] ;
274
279
this . _versionId = 0 ;
@@ -277,7 +282,8 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
277
282
const mainCells = cells . map ( cell => {
278
283
const cellHandle = this . _cellhandlePool ++ ;
279
284
const cellUri = CellUri . generate ( this . uri , cellHandle ) ;
280
- return new NotebookCellTextModel ( cellUri , cellHandle , cell . source , cell . language , cell . mime , cell . cellKind , cell . outputs , cell . metadata , cell . internalMetadata , this . transientOptions , this . _modeService ) ;
285
+ const collapseState = this . _getDefaultCollapseState ( cell ) ;
286
+ return new NotebookCellTextModel ( cellUri , cellHandle , cell . source , cell . language , cell . mime , cell . cellKind , cell . outputs , cell . metadata , cell . internalMetadata , collapseState , this . transientOptions , this . _modeService ) ;
281
287
} ) ;
282
288
283
289
for ( let i = 0 ; i < mainCells . length ; i ++ ) {
@@ -575,6 +581,11 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
575
581
return mergedEdits ;
576
582
}
577
583
584
+ private _getDefaultCollapseState ( cellDto : ICellDto2 ) : NotebookCellCollapseState | undefined {
585
+ const defaultConfig = cellDto . cellKind === CellKind . Code ? this . _defaultCollapseConfig ?. codeCell : this . _defaultCollapseConfig ?. markupCell ;
586
+ return cellDto . collapseState ?? ( defaultConfig ?? undefined ) ;
587
+ }
588
+
578
589
private _replaceCells ( index : number , count : number , cellDtos : ICellDto2 [ ] , synchronous : boolean , computeUndoRedo : boolean ) : void {
579
590
580
591
if ( count === 0 && cellDtos . length === 0 ) {
@@ -598,9 +609,10 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
598
609
const cells = cellDtos . map ( cellDto => {
599
610
const cellHandle = this . _cellhandlePool ++ ;
600
611
const cellUri = CellUri . generate ( this . uri , cellHandle ) ;
612
+ const collapseState = this . _getDefaultCollapseState ( cellDto ) ;
601
613
const cell = new NotebookCellTextModel (
602
614
cellUri , cellHandle ,
603
- cellDto . source , cellDto . language , cellDto . mime , cellDto . cellKind , cellDto . outputs || [ ] , cellDto . metadata , cellDto . internalMetadata , this . transientOptions ,
615
+ cellDto . source , cellDto . language , cellDto . mime , cellDto . cellKind , cellDto . outputs || [ ] , cellDto . metadata , cellDto . internalMetadata , collapseState , this . transientOptions ,
604
616
this . _modeService
605
617
) ;
606
618
const textModel = this . _modelService . getModel ( cellUri ) ;
0 commit comments