diff --git a/src/sql/workbench/contrib/notebook/browser/models/cell.ts b/src/sql/workbench/contrib/notebook/browser/models/cell.ts index 6224f108e7..7360c401a0 100644 --- a/src/sql/workbench/contrib/notebook/browser/models/cell.ts +++ b/src/sql/workbench/contrib/notebook/browser/models/cell.ts @@ -339,6 +339,8 @@ export class CellModel implements ICellModel { } let content = this.source; if ((Array.isArray(content) && content.length > 0) || (!Array.isArray(content) && content)) { + this.notebookModel.trustedMode = true; + // requestExecute expects a string for the code parameter content = Array.isArray(content) ? content.join('') : content; const future = kernel.requestExecute({ diff --git a/src/sql/workbench/contrib/notebook/browser/models/notebookModel.ts b/src/sql/workbench/contrib/notebook/browser/models/notebookModel.ts index 5f45020745..9a95e05567 100644 --- a/src/sql/workbench/contrib/notebook/browser/models/notebookModel.ts +++ b/src/sql/workbench/contrib/notebook/browser/models/notebookModel.ts @@ -308,6 +308,11 @@ export class NotebookModel extends Disposable implements INotebookModel { }); } } + + // Trust notebook by default if there are no code cells + if (this._cells.length === 0 || this._cells.every(cell => cell.cellType === CellTypes.Markdown)) { + this.trustedMode = true; + } } catch (error) { this._inErrorState = true; throw error; diff --git a/src/sql/workbench/contrib/notebook/browser/notebook.component.ts b/src/sql/workbench/contrib/notebook/browser/notebook.component.ts index ae6cd27453..72848ef9c7 100644 --- a/src/sql/workbench/contrib/notebook/browser/notebook.component.ts +++ b/src/sql/workbench/contrib/notebook/browser/notebook.component.ts @@ -21,8 +21,8 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import * as DOM from 'vs/base/browser/dom'; import { AngularDisposable } from 'sql/base/browser/lifecycle'; -import { CellTypes, CellType } from 'sql/workbench/contrib/notebook/common/models/contracts'; -import { ICellModel, IModelFactory, INotebookModel } from 'sql/workbench/contrib/notebook/browser/models/modelInterfaces'; +import { CellTypes, CellType, NotebookChangeType } from 'sql/workbench/contrib/notebook/common/models/contracts'; +import { ICellModel, IModelFactory, INotebookModel, NotebookContentChange } from 'sql/workbench/contrib/notebook/browser/models/modelInterfaces'; import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement'; import { INotebookService, INotebookParams, INotebookManager, INotebookEditor, DEFAULT_NOTEBOOK_PROVIDER, SQL_NOTEBOOK_PROVIDER, INotebookSection, INavigationProvider, ICellEditorProvider } from 'sql/workbench/services/notebook/browser/notebookService'; import { NotebookModel } from 'sql/workbench/contrib/notebook/browser/models/notebookModel'; @@ -309,7 +309,7 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe }, this.profile, this.logService, this.notificationService, this.telemetryService); let trusted = await this.notebookService.isNotebookTrustCached(this._notebookParams.notebookUri, this.isDirty()); this._register(model.onError((errInfo: INotification) => this.handleModelError(errInfo))); - this._register(model.contentChanged((change) => this.handleContentChanged())); + this._register(model.contentChanged((change) => this.handleContentChanged(change))); this._register(model.onProviderIdChange((provider) => this.handleProviderIdChanged(provider))); this._register(model.kernelChanged((kernelArgs) => this.handleKernelChanged(kernelArgs))); this._model = this._register(model); @@ -360,7 +360,11 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe this.notificationService.notify(notification); } - private handleContentChanged() { + private handleContentChanged(change: NotebookContentChange) { + if (change.changeType === NotebookChangeType.TrustChanged) { + this._trustedAction.trusted = this._model.trustedMode; + } + // Note: for now we just need to set dirty state and refresh the UI. this.detectChanges(); } diff --git a/src/sql/workbench/contrib/notebook/test/electron-browser/notebookModel.test.ts b/src/sql/workbench/contrib/notebook/test/electron-browser/notebookModel.test.ts index e88a5138e0..70c438b438 100644 --- a/src/sql/workbench/contrib/notebook/test/electron-browser/notebookModel.test.ts +++ b/src/sql/workbench/contrib/notebook/test/electron-browser/notebookModel.test.ts @@ -155,8 +155,9 @@ suite('notebook model', function (): void { // Then I expect to have 0 code cell as the contents assert.equal(model.cells.length, 0); - // And Trust should be false by default - assert(!model.trustedMode); + + // And Trust should be true by default if there are no cells + assert(model.trustedMode); }); test('Should use trusted state set in model load', async function (): Promise {