@@ -8,10 +8,10 @@ import { Emitter, Event } from 'vs/base/common/event';
88import { Disposable , IDisposable } from 'vs/base/common/lifecycle' ;
99import { URI } from 'vs/base/common/uri' ;
1010import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel' ;
11- import { INotebookTextModel , NotebookCellOutputsSplice , NotebookCellTextModelSplice , NotebookDocumentMetadata , NotebookCellMetadata , ICellEditOperation , CellEditType , CellUri , NotebookCellsChangedEvent , CellKind , IProcessedOutput , notebookDocumentMetadataDefaults , diff , NotebookCellsChangeType , ICellDto2 , IMainCellDto } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
11+ import { INotebookTextModel , NotebookCellOutputsSplice , NotebookCellTextModelSplice , NotebookDocumentMetadata , NotebookCellMetadata , ICellEditOperation , CellEditType , CellUri , NotebookCellsChangedEvent , CellKind , IProcessedOutput , notebookDocumentMetadataDefaults , diff , NotebookCellsChangeType , ICellDto2 , IMainCellDto , TransientMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
1212import { ITextSnapshot } from 'vs/editor/common/model' ;
1313import { IUndoRedoService , UndoRedoElementType , IUndoRedoElement , IResourceUndoRedoElement } from 'vs/platform/undoRedo/common/undoRedo' ;
14- import { InsertCellEdit , DeleteCellEdit , MoveCellEdit , SpliceCellsEdit } from 'vs/workbench/contrib/notebook/common/model/cellEdit' ;
14+ import { InsertCellEdit , DeleteCellEdit , MoveCellEdit , SpliceCellsEdit , CellMetadataEdit } from 'vs/workbench/contrib/notebook/common/model/cellEdit' ;
1515import { ITextModelService } from 'vs/editor/common/services/resolverService' ;
1616
1717export class NotebookTextModelSnapshot implements ITextSnapshot {
@@ -128,6 +128,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
128128 cells : NotebookCellTextModel [ ] ;
129129 languages : string [ ] = [ ] ;
130130 metadata : NotebookDocumentMetadata = notebookDocumentMetadataDefaults ;
131+ transientMetadata : TransientMetadata = { } ;
131132 private _isUntitled : boolean | undefined = undefined ;
132133 private _versionId = 0 ;
133134
@@ -259,7 +260,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
259260 break ;
260261 case CellEditType . Metadata :
261262 this . assertIndex ( edit . index ) ;
262- this . changeCellMetadata ( this . cells [ edit . index ] . handle , edit . metadata ) ;
263+ this . deltaCellMetadata ( this . cells [ edit . index ] . handle , edit . metadata ) ;
263264 break ;
264265 }
265266 }
@@ -342,14 +343,6 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
342343 this . _onDidChangeMetadata . fire ( this . metadata ) ;
343344 }
344345
345- updateNotebookCellMetadata ( handle : number , metadata : NotebookCellMetadata ) {
346- const cell = this . cells . find ( cell => cell . handle === handle ) ;
347-
348- if ( cell ) {
349- cell . metadata = metadata ;
350- }
351- }
352-
353346 insertTemplateCell ( cell : NotebookCellTextModel ) {
354347 if ( this . cells . length > 0 || this . _isUntitled !== undefined ) {
355348 return ;
@@ -504,16 +497,99 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
504497 }
505498 }
506499
507- changeCellMetadata ( handle : number , newMetadata : NotebookCellMetadata ) {
500+ private _compareCellMetadata ( a : NotebookCellMetadata | undefined , b : NotebookCellMetadata | undefined ) {
501+ if ( a ?. editable !== b ?. editable && ! this . transientMetadata . editable ) {
502+ return true ;
503+ }
504+
505+ if ( a ?. runnable !== b ?. runnable && ! this . transientMetadata . runnable ) {
506+ return true ;
507+ }
508+
509+ if ( a ?. breakpointMargin !== b ?. breakpointMargin && ! this . transientMetadata . breakpointMargin ) {
510+ return true ;
511+ }
512+
513+ if ( a ?. hasExecutionOrder !== b ?. hasExecutionOrder && ! this . transientMetadata . hasExecutionOrder ) {
514+ return true ;
515+ }
516+
517+ if ( a ?. executionOrder !== b ?. executionOrder && ! this . transientMetadata . executionOrder ) {
518+ return true ;
519+ }
520+
521+ if ( a ?. statusMessage !== b ?. statusMessage && ! this . transientMetadata . statusMessage ) {
522+ return true ;
523+ }
524+
525+ if ( a ?. runState !== b ?. runState && ! this . transientMetadata . runState ) {
526+ return true ;
527+ }
528+
529+ if ( a ?. runStartTime !== b ?. runStartTime && ! this . transientMetadata . runStartTime ) {
530+ return true ;
531+ }
532+
533+ if ( a ?. lastRunDuration !== b ?. lastRunDuration && ! this . transientMetadata . lastRunDuration ) {
534+ return true ;
535+ }
536+
537+ if ( a ?. inputCollapsed !== b ?. inputCollapsed && ! this . transientMetadata . inputCollapsed ) {
538+ return true ;
539+ }
540+
541+ if ( a ?. outputCollapsed !== b ?. outputCollapsed && ! this . transientMetadata . outputCollapsed ) {
542+ return true ;
543+ }
544+
545+ if ( a ?. custom !== b ?. custom && ! this . transientMetadata . custom ) {
546+ return true ;
547+ }
548+
549+ return false ;
550+ }
551+
552+ changeCellMetadata ( handle : number , metadata : NotebookCellMetadata | undefined , pushUndoStop : boolean ) {
553+ const cell = this . cells . find ( cell => cell . handle === handle ) ;
554+
555+ if ( ! cell ) {
556+ return ;
557+ }
558+
559+ const triggerDirtyChange = this . _compareCellMetadata ( cell . metadata , metadata ) ;
560+
561+ if ( triggerDirtyChange ) {
562+ if ( pushUndoStop ) {
563+ const index = this . cells . indexOf ( cell ) ;
564+ this . _operationManager . pushEditOperation ( new CellMetadataEdit ( this . uri , index , Object . freeze ( cell . metadata ) , Object . freeze ( metadata ) , {
565+ updateCellMetadata : ( index , newMetadata ) => {
566+ const cell = this . cells [ index ] ;
567+ if ( ! cell ) {
568+ return ;
569+ }
570+ this . changeCellMetadata ( cell . handle , newMetadata , false ) ;
571+ } ,
572+ emitSelections : this . _emitSelectionsDelegate . bind ( this )
573+ } ) ) ;
574+ }
575+ cell . metadata = metadata ;
576+ this . setDirty ( true ) ;
577+ this . _onDidChangeContent . fire ( ) ;
578+ } else {
579+ cell . metadata = metadata ;
580+ }
581+
582+ this . _increaseVersionId ( ) ;
583+ this . _onDidModelChangeProxy . fire ( { kind : NotebookCellsChangeType . ChangeMetadata , versionId : this . _versionId , index : this . cells . indexOf ( cell ) , metadata : cell . metadata } ) ;
584+ }
585+
586+ deltaCellMetadata ( handle : number , newMetadata : NotebookCellMetadata ) {
508587 const cell = this . _mapping . get ( handle ) ;
509588 if ( cell ) {
510- cell . metadata = {
589+ this . changeCellMetadata ( handle , {
511590 ...cell . metadata ,
512591 ...newMetadata
513- } ;
514-
515- this . _increaseVersionId ( ) ;
516- this . _onDidModelChangeProxy . fire ( { kind : NotebookCellsChangeType . ChangeMetadata , versionId : this . _versionId , index : this . cells . indexOf ( cell ) , metadata : cell . metadata } ) ;
592+ } , true ) ;
517593 }
518594 }
519595
0 commit comments