@@ -96,6 +96,7 @@ export class NotebookModel implements Saveable, Disposable {
96
96
protected nextHandle : number = 0 ;
97
97
98
98
protected _dirty = false ;
99
+ protected _lastData ?: NotebookData ;
99
100
100
101
set dirty ( dirty : boolean ) {
101
102
const oldState = this . _dirty ;
@@ -132,6 +133,8 @@ export class NotebookModel implements Saveable, Disposable {
132
133
initialize ( ) : void {
133
134
this . dirty = false ;
134
135
136
+ this . _lastData = this . props . data ;
137
+
135
138
this . cells = this . props . data . cells . map ( ( cell , index ) => this . cellModelFactory ( {
136
139
uri : CellUri . generate ( this . props . resource . uri , index ) ,
137
140
handle : index ,
@@ -165,10 +168,9 @@ export class NotebookModel implements Saveable, Disposable {
165
168
this . dirtyCells = [ ] ;
166
169
this . dirty = false ;
167
170
168
- const serializedNotebook = await this . props . serializer . fromNotebook ( {
169
- cells : this . cells . map ( cell => cell . getData ( ) ) ,
170
- metadata : this . metadata
171
- } ) ;
171
+ const data = this . getData ( ) ;
172
+ this . _lastData = data ;
173
+ const serializedNotebook = await this . props . serializer . fromNotebook ( data ) ;
172
174
this . fileService . writeFile ( this . uri , serializedNotebook ) ;
173
175
174
176
this . onDidSaveNotebookEmitter . fire ( ) ;
@@ -178,10 +180,7 @@ export class NotebookModel implements Saveable, Disposable {
178
180
const model = this ;
179
181
return {
180
182
read ( ) : string {
181
- return JSON . stringify ( {
182
- cells : model . cells . map ( cell => cell . getData ( ) ) ,
183
- metadata : model . metadata
184
- } ) ;
183
+ return JSON . stringify ( model . getData ( ) ) ;
185
184
}
186
185
} ;
187
186
}
@@ -192,10 +191,14 @@ export class NotebookModel implements Saveable, Disposable {
192
191
throw new Error ( 'could not read notebook snapshot' ) ;
193
192
}
194
193
const data = JSON . parse ( rawData ) as NotebookData ;
194
+ this . _lastData = data ;
195
195
this . setData ( data ) ;
196
196
}
197
197
198
198
async revert ( options ?: Saveable . RevertOptions ) : Promise < void > {
199
+ if ( this . _lastData && ! options ?. soft ) {
200
+ this . setData ( this . _lastData ) ;
201
+ }
199
202
this . dirty = false ;
200
203
}
201
204
@@ -217,10 +220,17 @@ export class NotebookModel implements Saveable, Disposable {
217
220
// Replace all cells in the model
218
221
this . replaceCells ( 0 , this . cells . length , data . cells , false ) ;
219
222
this . metadata = data . metadata ;
220
- this . dirty = false ;
223
+ this . dirty = true ;
221
224
this . onDidChangeContentEmitter . fire ( ) ;
222
225
}
223
226
227
+ getData ( ) : NotebookData {
228
+ return {
229
+ cells : this . cells . map ( cell => cell . getData ( ) ) ,
230
+ metadata : this . metadata
231
+ } ;
232
+ }
233
+
224
234
undo ( ) : void {
225
235
// TODO we probably need to check if a monaco editor is focused and if so, not undo
226
236
this . undoRedoService . undo ( this . uri ) ;
@@ -263,7 +273,7 @@ export class NotebookModel implements Saveable, Disposable {
263
273
end : edit . editType === CellEditType . Replace ? edit . index + edit . count : cellIndex ,
264
274
originalIndex : index
265
275
} ;
266
- } ) . filter ( edit => ! ! edit ) ;
276
+ } ) ;
267
277
268
278
for ( const { edit, cellIndex } of editsWithDetails ) {
269
279
const cell = this . cells [ cellIndex ] ;
0 commit comments