@@ -49,8 +49,8 @@ class StackOperation implements IWorkspaceUndoRedoElement {
4949 constructor (
5050 readonly textModel : NotebookTextModel ,
5151 readonly undoRedoGroup : UndoRedoGroup | undefined ,
52- private _pauseableEmitter : PauseableEmitter < NotebookTextModelChangedEvent > ,
53- private _postUndoRedo : ( alternativeVersionId : string ) => void ,
52+ private readonly _pauseableEmitter : PauseableEmitter < NotebookTextModelChangedEvent > ,
53+ private readonly _postUndoRedo : ( alternativeVersionId : string ) => void ,
5454 selectionState : ISelectionState | undefined ,
5555 beginAlternativeVersionId : string
5656 ) {
@@ -621,32 +621,35 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
621621
622622 applyEdits ( rawEdits : ICellEditOperation [ ] , synchronous : boolean , beginSelectionState : ISelectionState | undefined , endSelectionsComputer : ( ) => ISelectionState | undefined , undoRedoGroup : UndoRedoGroup | undefined , computeUndoRedo : boolean ) : boolean {
623623 this . _pauseableEmitter . pause ( ) ;
624- this . _operationManager . pushStackElement ( this . _alternativeVersionId , undefined ) ;
624+ try {
625+ this . _operationManager . pushStackElement ( this . _alternativeVersionId , undefined ) ;
625626
626- if ( computeUndoRedo && this . isOnlyEditingMetadataOnNewCells ( rawEdits ) ) {
627- if ( ! this . _operationManager . appendPreviousOperation ( ) ) {
628- // we can't append the previous operation, so just don't compute undo/redo
629- computeUndoRedo = false ;
627+ if ( computeUndoRedo && this . isOnlyEditingMetadataOnNewCells ( rawEdits ) ) {
628+ if ( ! this . _operationManager . appendPreviousOperation ( ) ) {
629+ // we can't append the previous operation, so just don't compute undo/redo
630+ computeUndoRedo = false ;
631+ }
632+ } else if ( computeUndoRedo ) {
633+ this . newCellsFromLastEdit . clear ( ) ;
630634 }
631- } else if ( computeUndoRedo ) {
632- this . newCellsFromLastEdit . clear ( ) ;
633- }
634635
635- try {
636- this . _doApplyEdits ( rawEdits , synchronous , computeUndoRedo , beginSelectionState , undoRedoGroup ) ;
637- return true ;
638- } finally {
639- if ( ! this . _pauseableEmitter . isEmpty ) {
640- // Update selection and versionId after applying edits.
641- const endSelections = endSelectionsComputer ( ) ;
642- this . _increaseVersionId ( this . _operationManager . isUndoStackEmpty ( ) && ! this . _pauseableEmitter . isDirtyEvent ( ) ) ;
636+ try {
637+ this . _doApplyEdits ( rawEdits , synchronous , computeUndoRedo , beginSelectionState , undoRedoGroup ) ;
638+ return true ;
639+ } finally {
640+ if ( ! this . _pauseableEmitter . isEmpty ) {
641+ // Update selection and versionId after applying edits.
642+ const endSelections = endSelectionsComputer ( ) ;
643+ this . _increaseVersionId ( this . _operationManager . isUndoStackEmpty ( ) && ! this . _pauseableEmitter . isDirtyEvent ( ) ) ;
643644
644- // Finalize undo element
645- this . _operationManager . pushStackElement ( this . _alternativeVersionId , endSelections ) ;
645+ // Finalize undo element
646+ this . _operationManager . pushStackElement ( this . _alternativeVersionId , endSelections ) ;
646647
647- // Broadcast changes
648- this . _pauseableEmitter . fire ( { rawEvents : [ ] , versionId : this . versionId , synchronous : synchronous , endSelectionState : endSelections } ) ;
648+ // Broadcast changes
649+ this . _pauseableEmitter . fire ( { rawEvents : [ ] , versionId : this . versionId , synchronous : synchronous , endSelectionState : endSelections } ) ;
650+ }
649651 }
652+ } finally {
650653 this . _pauseableEmitter . resume ( ) ;
651654 }
652655 }
0 commit comments