From dd58b1fe2bf3e40a4b75f30ec9e92982f2c3d994 Mon Sep 17 00:00:00 2001 From: rebornix Date: Thu, 29 Apr 2021 13:33:41 -0700 Subject: [PATCH] fix #121647 --- .../notebook/browser/notebookEditorWidget.ts | 10 ++++++++++ .../browser/viewModel/codeCellViewModel.ts | 14 ++++++++++++++ .../browser/viewModel/markdownCellViewModel.ts | 9 +++++++++ 3 files changed, 33 insertions(+) diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts index 50eeeed7a3a..28629a455f9 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts @@ -1185,6 +1185,16 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor store.add((cell as CodeCellViewModel).onDidRemoveOutputs((outputs) => { outputs.forEach(output => this.removeInset(output)); })); + + store.add((cell as CodeCellViewModel).onDidHideOutputs((outputs) => { + outputs.forEach(output => this.hideInset(output)); + })); + } + + if (cell.cellKind === CellKind.Markdown) { + store.add((cell as MarkdownCellViewModel).onDidHideInput(() => { + this.hideMarkdownPreviews([(cell as MarkdownCellViewModel)]); + })); } return store; diff --git a/src/vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel.ts b/src/vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel.ts index 836494d37bf..64356b4f63a 100644 --- a/src/vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel.ts +++ b/src/vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel.ts @@ -24,6 +24,10 @@ export class CodeCellViewModel extends BaseCellViewModel implements ICellViewMod readonly onDidChangeOutputs = this._onDidChangeOutputs.event; private readonly _onDidRemoveOutputs = new Emitter(); readonly onDidRemoveOutputs = this._onDidRemoveOutputs.event; + private readonly _onDidHideInput = new Emitter(); + readonly onDidHideInput = this._onDidHideInput.event; + private readonly _onDidHideOutputs = new Emitter(); + readonly onDidHideOutputs = this._onDidHideOutputs.event; private _outputCollection: number[] = []; private _outputsTop: PrefixSumComputer | null = null; @@ -113,6 +117,16 @@ export class CodeCellViewModel extends BaseCellViewModel implements ICellViewMod this.layoutChange({ outputHeight: true }, 'CodeCellViewModel#model.onDidChangeOutputs'); })); + this._register(this.model.onDidChangeMetadata(e => { + if (this.metadata?.outputCollapsed) { + this._onDidHideOutputs.fire(this.outputsViewModels.slice(0)); + } + + if (this.metadata?.inputCollapsed) { + this._onDidHideInput.fire(); + } + })); + this._outputCollection = new Array(this.model.outputs.length); this._layoutInfo = { diff --git a/src/vs/workbench/contrib/notebook/browser/viewModel/markdownCellViewModel.ts b/src/vs/workbench/contrib/notebook/browser/viewModel/markdownCellViewModel.ts index 39830c38a99..7bf8336a374 100644 --- a/src/vs/workbench/contrib/notebook/browser/viewModel/markdownCellViewModel.ts +++ b/src/vs/workbench/contrib/notebook/browser/viewModel/markdownCellViewModel.ts @@ -94,6 +94,9 @@ export class MarkdownCellViewModel extends BaseCellViewModel implements ICellVie return this.model.getHashValue(); } + private readonly _onDidHideInput = new Emitter(); + readonly onDidHideInput = this._onDidHideInput.event; + constructor( viewType: string, model: NotebookCellTextModel, @@ -117,6 +120,12 @@ export class MarkdownCellViewModel extends BaseCellViewModel implements ICellVie this._register(this.onDidChangeState(e => { eventDispatcher.emit([new NotebookCellStateChangedEvent(e, this)]); })); + + this._register(model.onDidChangeMetadata(e => { + if (this.metadata?.inputCollapsed) { + this._onDidHideInput.fire(); + } + })); } /** -- GitLab