@@ -32,6 +32,7 @@ import { IPosition, Position } from 'vs/editor/common/core/position';
32
32
import { SplitCellEdit , JoinCellEdit } from 'vs/workbench/contrib/notebook/browser/viewModel/cellEdit' ;
33
33
import { BaseCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/baseCellViewModel' ;
34
34
import { PieceTreeTextBuffer } from 'vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBuffer' ;
35
+ import { MultiModelEditStackElement , SingleModelEditStackElement } from 'vs/editor/common/model/editStack' ;
35
36
36
37
export interface INotebookEditorViewState {
37
38
editingCells : { [ key : number ] : boolean } ;
@@ -1051,12 +1052,38 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD
1051
1052
} ) ;
1052
1053
}
1053
1054
1055
+ async withElement ( element : SingleModelEditStackElement | MultiModelEditStackElement , callback : ( ) => Promise < void > ) {
1056
+ const viewCells = this . _viewCells . filter ( cell => element . matchesResource ( cell . uri ) ) ;
1057
+ const refs = await Promise . all ( viewCells . map ( cell => cell . model . resolveTextModelRef ( ) ) ) ;
1058
+ await callback ( ) ;
1059
+ refs . forEach ( ref => ref . dispose ( ) ) ;
1060
+ }
1061
+
1054
1062
async undo ( ) {
1063
+ const editStack = this . _undoService . getElements ( this . uri ) ;
1064
+ const element = editStack . past . length ? editStack . past [ editStack . past . length - 1 ] : undefined ;
1065
+
1066
+ if ( element && element instanceof SingleModelEditStackElement || element instanceof MultiModelEditStackElement ) {
1067
+ return await this . withElement ( element , async ( ) => {
1068
+ await this . _undoService . undo ( this . uri ) ;
1069
+ } ) ;
1070
+ }
1071
+
1055
1072
await this . _undoService . undo ( this . uri ) ;
1056
1073
}
1057
1074
1058
1075
async redo ( ) {
1076
+ const editStack = this . _undoService . getElements ( this . uri ) ;
1077
+ const element = editStack . future [ 0 ] ;
1078
+
1079
+ if ( element && element instanceof SingleModelEditStackElement || element instanceof MultiModelEditStackElement ) {
1080
+ return await this . withElement ( element , async ( ) => {
1081
+ await this . _undoService . redo ( this . uri ) ;
1082
+ } ) ;
1083
+ }
1084
+
1059
1085
await this . _undoService . redo ( this . uri ) ;
1086
+
1060
1087
}
1061
1088
1062
1089
equal ( notebook : NotebookTextModel ) {
0 commit comments