From 759ead4d71ebc9fe02bf1a02f24dfc648b3ca281 Mon Sep 17 00:00:00 2001 From: rebornix Date: Thu, 3 Sep 2020 21:22:18 -0700 Subject: [PATCH] remove onDidChangeMetadata. --- .../workbench/api/common/extHostNotebook.ts | 2 +- .../browser/viewModel/notebookViewModel.ts | 8 +++-- .../common/model/notebookTextModel.ts | 32 +++++++++---------- .../contrib/notebook/common/notebookCommon.ts | 21 +++++++++--- 4 files changed, 38 insertions(+), 25 deletions(-) diff --git a/src/vs/workbench/api/common/extHostNotebook.ts b/src/vs/workbench/api/common/extHostNotebook.ts index 0c4bf7c66aa..dc1c5fa374a 100644 --- a/src/vs/workbench/api/common/extHostNotebook.ts +++ b/src/vs/workbench/api/common/extHostNotebook.ts @@ -333,7 +333,7 @@ export class ExtHostNotebookDocument extends Disposable { this._clearAllCellOutputs(); } else if (event.kind === NotebookCellsChangeType.ChangeLanguage) { this._changeCellLanguage(event.index, event.language); - } else if (event.kind === NotebookCellsChangeType.ChangeMetadata) { + } else if (event.kind === NotebookCellsChangeType.ChangeCellMetadata) { this._changeCellMetadata(event.index, event.metadata); } } diff --git a/src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel.ts b/src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel.ts index 15d2b30af18..87bf0ef6e87 100644 --- a/src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel.ts +++ b/src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel.ts @@ -23,7 +23,7 @@ import { NotebookEventDispatcher, NotebookMetadataChangedEvent } from 'vs/workbe import { CellFoldingState, EditorFoldingStateDelegate } from 'vs/workbench/contrib/notebook/browser/contrib/fold/foldingModel'; import { MarkdownCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/markdownCellViewModel'; import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel'; -import { CellKind, NotebookCellMetadata, INotebookSearchOptions, ICellRange } from 'vs/workbench/contrib/notebook/common/notebookCommon'; +import { CellKind, NotebookCellMetadata, INotebookSearchOptions, ICellRange, NotebookCellsChangeType } from 'vs/workbench/contrib/notebook/common/notebookCommon'; import { FoldingRegions } from 'vs/editor/contrib/folding/foldingRanges'; import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel'; import { MarkdownRenderer } from 'vs/workbench/contrib/notebook/browser/view/renderers/mdRenderer'; @@ -308,8 +308,10 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD this.selectionHandles = endSelectionHandles; })); - this._register(this._notebook.onDidChangeMetadata(e => { - this.eventDispatcher.emit([new NotebookMetadataChangedEvent(e)]); + this._register(this._notebook.onDidChangeContent(e => { + if (e === NotebookCellsChangeType.ChangeDocumentMetadata) { + this.eventDispatcher.emit([new NotebookMetadataChangedEvent(this._notebook.metadata)]); + } })); this._register(this._notebook.emitSelections(selections => { diff --git a/src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts b/src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts index f1d0dcaa0a4..93d0a344a69 100644 --- a/src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts +++ b/src/vs/workbench/contrib/notebook/common/model/notebookTextModel.ts @@ -118,10 +118,8 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel get emitSelections() { return this._emitSelections.event; } private _onDidModelChangeProxy = this._register(new Emitter()); get onDidModelChangeProxy(): Event { return this._onDidModelChangeProxy.event; } - private _onDidChangeContent = this._register(new Emitter()); - onDidChangeContent: Event = this._onDidChangeContent.event; - private _onDidChangeMetadata = this._register(new Emitter()); - onDidChangeMetadata: Event = this._onDidChangeMetadata.event; + private _onDidChangeContent = this._register(new Emitter()); + onDidChangeContent: Event = this._onDidChangeContent.event; private _mapping: Map = new Map(); private _cellListeners: Map = new Map(); cells: NotebookCellTextModel[]; @@ -210,7 +208,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel const dirtyStateListener = mainCells[i].onDidChangeContent(() => { this.setDirty(true); this._increaseVersionId(); - this._onDidChangeContent.fire(); + this._onDidChangeContent.fire(NotebookCellsChangeType.ChangeCellContent); }); this._cellListeners.set(mainCells[i].handle, dirtyStateListener); @@ -324,7 +322,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel const dirtyStateListener = cell.onDidChangeContent(() => { this.setDirty(true); this._increaseVersionId(); - this._onDidChangeContent.fire(); + this._onDidChangeContent.fire(NotebookCellsChangeType.ChangeCellContent); }); this._cellListeners.set(cell.handle, dirtyStateListener); this._mapping.set(cell.handle, cell); @@ -335,7 +333,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel this.cells.splice(index, count, ...cells); this.setDirty(true); this._increaseVersionId(); - this._onDidChangeContent.fire(); + this._onDidChangeContent.fire(NotebookCellsChangeType.ModelChange); } handleEdit(label: string | undefined, undo: () => void, redo: () => void): void { @@ -378,7 +376,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel updateNotebookMetadata(metadata: NotebookDocumentMetadata) { this.metadata = metadata; - this._onDidChangeMetadata.fire(this.metadata); + this._onDidChangeContent.fire(NotebookCellsChangeType.ChangeDocumentMetadata); } insertTemplateCell(cell: NotebookCellTextModel) { @@ -394,12 +392,12 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel this._isUntitled = false; this.setDirty(true); this._increaseVersionId(); - this._onDidChangeContent.fire(); + this._onDidChangeContent.fire(NotebookCellsChangeType.ChangeCellContent); }); this._cellListeners.set(cell.handle, dirtyStateListener); this.setDirty(false); - this._onDidChangeContent.fire(); + this._onDidChangeContent.fire(NotebookCellsChangeType.ModelChange); this._onDidModelChangeProxy.fire({ kind: NotebookCellsChangeType.ModelChange, @@ -431,7 +429,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel const dirtyStateListener = cells[i].onDidChangeContent(() => { this.setDirty(true); this._increaseVersionId(); - this._onDidChangeContent.fire(); + this._onDidChangeContent.fire(NotebookCellsChangeType.ChangeCellContent); }); this._cellListeners.set(cells[i].handle, dirtyStateListener); @@ -439,7 +437,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel this.cells.splice(index, 0, ...cells); this.setDirty(true); - this._onDidChangeContent.fire(); + this._onDidChangeContent.fire(NotebookCellsChangeType.ModelChange); this._increaseVersionId(); @@ -475,7 +473,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel } this.cells.splice(index, count); this.setDirty(true); - this._onDidChangeContent.fire(); + this._onDidChangeContent.fire(NotebookCellsChangeType.ModelChange); this._increaseVersionId(); this._onDidModelChangeProxy.fire({ kind: NotebookCellsChangeType.ModelChange, versionId: this._versionId, changes: [[index, count, []]] }); @@ -488,7 +486,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel const cells = this.cells.splice(index, length); this.cells.splice(newIdx, 0, ...cells); this.setDirty(true); - this._onDidChangeContent.fire(); + this._onDidChangeContent.fire(NotebookCellsChangeType.Move); this._increaseVersionId(); this._onDidModelChangeProxy.fire({ kind: NotebookCellsChangeType.Move, versionId: this._versionId, index, newIdx }); @@ -510,7 +508,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel if (!this.transientOptions.transientOutputs) { this._increaseVersionId(); this.setDirty(true); - this._onDidChangeContent.fire(); + this._onDidChangeContent.fire(NotebookCellsChangeType.Output); } this._onDidModelChangeProxy.fire({ @@ -585,13 +583,13 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel } cell.metadata = metadata; this.setDirty(true); - this._onDidChangeContent.fire(); + this._onDidChangeContent.fire(NotebookCellsChangeType.ChangeCellMetadata); } else { cell.metadata = metadata; } this._increaseVersionId(); - this._onDidModelChangeProxy.fire({ kind: NotebookCellsChangeType.ChangeMetadata, versionId: this._versionId, index: this.cells.indexOf(cell), metadata: cell.metadata }); + this._onDidModelChangeProxy.fire({ kind: NotebookCellsChangeType.ChangeCellMetadata, versionId: this._versionId, index: this.cells.indexOf(cell), metadata: cell.metadata }); } deltaCellMetadata(handle: number, newMetadata: NotebookCellMetadata) { diff --git a/src/vs/workbench/contrib/notebook/common/notebookCommon.ts b/src/vs/workbench/contrib/notebook/common/notebookCommon.ts index e13425768bf..b598294f6c9 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookCommon.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookCommon.ts @@ -278,7 +278,7 @@ export interface INotebookTextModel { languages: string[]; cells: ICell[]; onDidChangeCells?: Event<{ synchronous: boolean, splices: NotebookCellTextModelSplice[] }>; - onDidChangeContent: Event; + onDidChangeContent: Event; onWillDispose(listener: () => void): IDisposable; } @@ -348,8 +348,10 @@ export enum NotebookCellsChangeType { CellsClearOutput = 4, ChangeLanguage = 5, Initialize = 6, - ChangeMetadata = 7, + ChangeCellMetadata = 7, Output = 8, + ChangeCellContent = 9, + ChangeDocumentMetadata = 10 } export interface NotebookCellsInitializeEvent { @@ -358,6 +360,11 @@ export interface NotebookCellsInitializeEvent { readonly versionId: number; } +export interface NotebookCellContentChangeEvent { + readonly kind: NotebookCellsChangeType.ChangeCellContent; + readonly versionId: number; +} + export interface NotebookCellsModelChangedEvent { readonly kind: NotebookCellsChangeType.ModelChange; readonly changes: NotebookCellsSplice2[]; @@ -397,13 +404,19 @@ export interface NotebookCellsChangeLanguageEvent { } export interface NotebookCellsChangeMetadataEvent { - readonly kind: NotebookCellsChangeType.ChangeMetadata; + readonly kind: NotebookCellsChangeType.ChangeCellMetadata; readonly versionId: number; readonly index: number; readonly metadata: NotebookCellMetadata | undefined; } -export type NotebookCellsChangedEvent = NotebookCellsInitializeEvent | NotebookCellsModelChangedEvent | NotebookCellsModelMoveEvent | NotebookOutputChangedEvent | NotebookCellClearOutputEvent | NotebookCellsClearOutputEvent | NotebookCellsChangeLanguageEvent | NotebookCellsChangeMetadataEvent; +export interface NotebookDocumentChangeMetadataEvent { + readonly kind: NotebookCellsChangeType.ChangeDocumentMetadata; + readonly versionId: number; + readonly metadata: NotebookDocumentMetadata | undefined; +} + +export type NotebookCellsChangedEvent = NotebookCellsInitializeEvent | NotebookDocumentChangeMetadataEvent | NotebookCellContentChangeEvent | NotebookCellsModelChangedEvent | NotebookCellsModelMoveEvent | NotebookOutputChangedEvent | NotebookCellClearOutputEvent | NotebookCellsClearOutputEvent | NotebookCellsChangeLanguageEvent | NotebookCellsChangeMetadataEvent; export const enum CellEditType { Replace = 1,