@@ -282,10 +282,10 @@ export class NativeEditorStorage implements INotebookStorage {
282
282
const dirtyContents = skipDirtyContents ? undefined : await this . getStoredContents ( file , backupId ) ;
283
283
if ( dirtyContents ) {
284
284
// This means we're dirty. Indicate dirty and load from this content
285
- return this . loadContents ( file , dirtyContents , true , contents , forVSCodeNotebook ) ;
285
+ return this . loadContents ( file , dirtyContents , true , forVSCodeNotebook ) ;
286
286
} else {
287
287
// Load without setting dirty
288
- return this . loadContents ( file , contents , undefined , undefined , forVSCodeNotebook ) ;
288
+ return this . loadContents ( file , contents , undefined , forVSCodeNotebook ) ;
289
289
}
290
290
} catch ( ex ) {
291
291
// May not exist at this time. Should always have a single cell though
@@ -308,7 +308,6 @@ export class NativeEditorStorage implements INotebookStorage {
308
308
file : Uri ,
309
309
contents : string | undefined ,
310
310
isInitiallyDirty = false ,
311
- trueContents ?: string ,
312
311
forVSCodeNotebook ?: boolean
313
312
) {
314
313
// tslint:disable-next-line: no-any
@@ -348,18 +347,9 @@ export class NativeEditorStorage implements INotebookStorage {
348
347
}
349
348
const pythonNumber = json ? await this . extractPythonMainVersion ( json ) : 3 ;
350
349
351
- /* As an optimization, we don't call trustNotebook for hot exit, since our hot exit backup code gets called by VS
352
- Code whenever the notebook model changes. This means it's called very often, perhaps even as often as autosave.
353
- Instead, when loading a file that is dirty, we check if the actual file contents on disk are trusted. If so, we treat
354
- the dirty contents as trusted as well. */
355
- const contentsToCheck = isInitiallyDirty && trueContents !== undefined ? trueContents : contents ;
356
- const isTrusted =
357
- contents === undefined || isUntitledFile ( file )
358
- ? true // If no contents or untitled, this is a newly created file, so it should be trusted
359
- : await this . trustService . isNotebookTrusted ( file , contentsToCheck ! ) ;
360
- return this . factory . createModel (
350
+ const model = this . factory . createModel (
361
351
{
362
- trusted : isTrusted ,
352
+ trusted : true ,
363
353
file,
364
354
cells : remapped ,
365
355
notebookJson : json ,
@@ -369,6 +359,23 @@ export class NativeEditorStorage implements INotebookStorage {
369
359
} ,
370
360
forVSCodeNotebook
371
361
) ;
362
+
363
+ // If no contents or untitled, this is a newly created file
364
+ // If dirty, that means it's been edited before in our extension
365
+ if ( contents !== undefined && ! isUntitledFile ( file ) && ! isInitiallyDirty ) {
366
+ const isNotebookTrusted = await this . trustService . isNotebookTrusted ( file , model . getContent ( ) ) ;
367
+ if ( isNotebookTrusted !== model . isTrusted ) {
368
+ model . update ( {
369
+ source : 'user' ,
370
+ kind : 'updateTrust' ,
371
+ oldDirty : model . isDirty ,
372
+ newDirty : model . isDirty ,
373
+ isNotebookTrusted
374
+ } ) ;
375
+ }
376
+ }
377
+
378
+ return model ;
372
379
}
373
380
374
381
private getStaticStorageKey ( file : Uri ) : string {
0 commit comments