diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index a433e7d86d9..35d0c6481be 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -665,7 +665,7 @@ export interface ICellDto { language: string; cellKind: CellKind; outputs: IOutput[]; - metadata?: NotebookCellMetadata; + metadata: NotebookCellMetadata; } export type NotebookCellsSplice = [ diff --git a/src/vs/workbench/api/common/extHostNotebook.ts b/src/vs/workbench/api/common/extHostNotebook.ts index 96012a5c028..72b8dc90e79 100644 --- a/src/vs/workbench/api/common/extHostNotebook.ts +++ b/src/vs/workbench/api/common/extHostNotebook.ts @@ -33,7 +33,7 @@ export class ExtHostCell implements vscode.NotebookCell { public cellKind: CellKind, public language: string, outputs: any[], - public metadata: vscode.NotebookCellMetadata | undefined, + public metadata: vscode.NotebookCellMetadata, ) { this.source = this._content.split(/\r|\n|\r\n/g); this._outputs = outputs; @@ -341,6 +341,10 @@ export class ExtHostNotebookDocument extends Disposable implements vscode.Notebo } } +const notebookCellMetadataDefaults: vscode.NotebookCellMetadata = { + editable: true +}; + export class ExtHostNotebookEditor extends Disposable implements vscode.NotebookEditor { private _viewColumn: vscode.ViewColumn | undefined; private static _cellhandlePool: number = 0; @@ -382,6 +386,10 @@ export class ExtHostNotebookEditor extends Disposable implements vscode.Notebook createCell(content: string, language: string, type: CellKind, outputs: vscode.CellOutput[], metadata: vscode.NotebookCellMetadata | undefined): vscode.NotebookCell { const handle = ExtHostNotebookEditor._cellhandlePool++; const uri = CellUri.generate(this.document.uri, handle); + metadata = { + ...notebookCellMetadataDefaults, + ...(metadata || {}) + }; const cell = new ExtHostCell(handle, uri, content, type, language, outputs, metadata); return cell; } diff --git a/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts b/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts index 7531d38820c..eda85b6e49b 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts @@ -73,7 +73,7 @@ export interface ICellViewModel { runState: CellRunState; focusMode: CellFocusMode; getText(): string; - metadata: NotebookCellMetadata | undefined; + metadata: NotebookCellMetadata; } export interface INotebookEditor { diff --git a/src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts b/src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts index dca0b07d2c6..e6935bb44d5 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts @@ -203,7 +203,7 @@ export class MarkdownCellRenderer extends AbstractCellRenderer implements IListR const contextKeyService = this.contextKeyService.createScoped(templateData.container); contextKeyService.createKey(NOTEBOOK_CELL_TYPE_CONTEXT_KEY, 'markdown'); - contextKeyService.createKey(NOTEBOOK_CELL_EDITABLE_CONTEXT_KEY, element.metadata?.editable); + contextKeyService.createKey(NOTEBOOK_CELL_EDITABLE_CONTEXT_KEY, element.metadata.editable); contextKeyService.createKey(NOTEBOOK_EDITABLE_CONTEXT_KEY, this.notebookEditor.viewModel?.metadata?.editable); const toolbarActions = this.getCellToolbarActions(contextKeyService); @@ -344,7 +344,7 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende const contextKeyService = this.contextKeyService.createScoped(templateData.container); contextKeyService.createKey(NOTEBOOK_CELL_TYPE_CONTEXT_KEY, 'code'); - contextKeyService.createKey(NOTEBOOK_CELL_EDITABLE_CONTEXT_KEY, element.metadata?.editable); + contextKeyService.createKey(NOTEBOOK_CELL_EDITABLE_CONTEXT_KEY, element.metadata.editable); contextKeyService.createKey(NOTEBOOK_EDITABLE_CONTEXT_KEY, this.notebookEditor.viewModel?.metadata?.editable); const toolbarActions = this.getCellToolbarActions(contextKeyService); diff --git a/src/vs/workbench/contrib/notebook/common/model/notebookCellTextModel.ts b/src/vs/workbench/contrib/notebook/common/model/notebookCellTextModel.ts index 6b05e1a0da0..99ca6e14730 100644 --- a/src/vs/workbench/contrib/notebook/common/model/notebookCellTextModel.ts +++ b/src/vs/workbench/contrib/notebook/common/model/notebookCellTextModel.ts @@ -39,7 +39,7 @@ export class NotebookCellTextModel implements ICell { public language: string, public cellKind: CellKind, outputs: IOutput[], - public readonly metadata: NotebookCellMetadata | undefined + public readonly metadata: NotebookCellMetadata ) { this._outputs = outputs; } diff --git a/src/vs/workbench/contrib/notebook/common/notebookCommon.ts b/src/vs/workbench/contrib/notebook/common/notebookCommon.ts index a76f4cc9392..3a7c8b8fd30 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookCommon.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookCommon.ts @@ -130,7 +130,7 @@ export interface ICell { language: string; cellKind: CellKind; outputs: IOutput[]; - metadata?: NotebookCellMetadata; + metadata: NotebookCellMetadata; onDidChangeOutputs?: Event; resolveTextBufferFactory(): PieceTreeTextBufferFactory; // TODO@rebornix it should be later on replaced by moving textmodel resolution into CellTextModel diff --git a/src/vs/workbench/contrib/notebook/test/notebookViewModel.test.ts b/src/vs/workbench/contrib/notebook/test/notebookViewModel.test.ts index 5c3093c461f..d257f320283 100644 --- a/src/vs/workbench/contrib/notebook/test/notebookViewModel.test.ts +++ b/src/vs/workbench/contrib/notebook/test/notebookViewModel.test.ts @@ -41,8 +41,8 @@ suite('NotebookViewModel', () => { assert.equal(viewModel.viewCells.length, 3); assert.equal(viewModel.notebookDocument.cells.length, 3); assert.equal(viewModel.getViewCellIndex(cell), 1); - assert.equal(viewModel.viewCells[0].metadata?.editable, true); - assert.equal(viewModel.viewCells[0].metadata?.editable, false); + assert.equal(viewModel.viewCells[0].metadata.editable, true); + assert.equal(viewModel.viewCells[1].metadata.editable, false); viewModel.deleteCell(1, true); assert.equal(viewModel.viewCells.length, 2); diff --git a/src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts b/src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts index dc57c7712c4..288eb71783c 100644 --- a/src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts +++ b/src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts @@ -26,6 +26,11 @@ export class TestCell implements ICell { onDidChangeOutputs: Event = this._onDidChangeOutputs.event; private _isDirty: boolean = false; private _outputs: IOutput[]; + + get metadata(): NotebookCellMetadata { + return { editable: true }; + } + get outputs(): IOutput[] { return this._outputs; }