From 65273f89bc1289111fa8699ca8aa37fa3ec4dfa0 Mon Sep 17 00:00:00 2001 From: rebornix Date: Mon, 19 Apr 2021 17:54:40 -0700 Subject: [PATCH] fix output max height update for diff editor. --- .../browser/diff/notebookTextDiffEditor.ts | 23 ++++++++++++++++++- .../notebook/browser/notebookBrowser.ts | 2 +- .../notebook/browser/notebookEditorWidget.ts | 4 ++-- .../view/renderers/backLayerWebView.ts | 2 +- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/vs/workbench/contrib/notebook/browser/diff/notebookTextDiffEditor.ts b/src/vs/workbench/contrib/notebook/browser/diff/notebookTextDiffEditor.ts index 13f04c088e2..58b0fae01cd 100644 --- a/src/vs/workbench/contrib/notebook/browser/diff/notebookTextDiffEditor.ts +++ b/src/vs/workbench/contrib/notebook/browser/diff/notebookTextDiffEditor.ts @@ -483,7 +483,28 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD } } - scheduleOutputHeightAck() { } + scheduleOutputHeightAck(cellInfo: IDiffCellInfo, outputId: string, height: number) { + const diffElement = cellInfo.diffElement; + // const activeWebview = diffSide === DiffSide.Modified ? this._modifiedWebview : this._originalWebview; + let diffSide = DiffSide.Original; + + if (diffElement instanceof SideBySideDiffElementViewModel) { + const info = CellUri.parse(cellInfo.cellUri); + if (!info) { + return; + } + + diffSide = info.notebook.toString() === this._model?.original.resource.toString() ? DiffSide.Original : DiffSide.Modified; + } else { + diffSide = diffElement.type === 'insert' ? DiffSide.Modified : DiffSide.Original; + } + + const webview = diffSide === DiffSide.Modified ? this._modifiedWebview : this._originalWebview; + + DOM.scheduleAtNextAnimationFrame(() => { + webview?.ackHeight(cellInfo.cellId, outputId, height); + }, 10); + } private _computeModifiedLCS(change: IDiffChange, originalModel: NotebookTextModel, modifiedModel: NotebookTextModel) { const result: DiffElementViewModelBase[] = []; diff --git a/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts b/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts index 635346a0f09..de7f895509b 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts @@ -173,7 +173,7 @@ export interface ICommonNotebookEditor { focusNotebookCell(cell: IGenericCellViewModel, focus: 'editor' | 'container' | 'output', options?: IFocusNotebookCellOptions): void; focusNextNotebookCell(cell: IGenericCellViewModel, focus: 'editor' | 'container' | 'output'): void; updateOutputHeight(cellInfo: ICommonCellInfo, output: IDisplayOutputViewModel, height: number, isInit: boolean, source?: string): void; - scheduleOutputHeightAck(cellId: string, outputId: string, height: number): void; + scheduleOutputHeightAck(cellInfo: ICommonCellInfo, outputId: string, height: number): void; updateMarkdownCellHeight(cellId: string, height: number, isInit: boolean): void; setMarkdownCellEditState(cellId: string, editState: CellEditState): void; markdownCellDragStart(cellId: string, position: { clientY: number }): void; diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts index 65475c2c541..47676ed3841 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts @@ -2355,12 +2355,12 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor } } - scheduleOutputHeightAck(cellId: string, outputId: string, height: number) { + scheduleOutputHeightAck(cellInfo: ICommonCellInfo, outputId: string, height: number) { DOM.scheduleAtNextAnimationFrame(() => { this.updateScrollHeight(); this._debug('ack height', height); - this._webview?.ackHeight(cellId, outputId, height); + this._webview?.ackHeight(cellInfo.cellId, outputId, height); }, 10); } diff --git a/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts b/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts index 32b18482e71..ad5f137f8fd 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts @@ -874,7 +874,7 @@ var requirejs = (function() { if (resolvedResult) { const { cellInfo, output } = resolvedResult; this.notebookEditor.updateOutputHeight(cellInfo, output, height, !!update.init, 'webview#dimension'); - this.notebookEditor.scheduleOutputHeightAck(cellInfo.cellId, update.id, height); + this.notebookEditor.scheduleOutputHeightAck(cellInfo, update.id, height); } } else { this.notebookEditor.updateMarkdownCellHeight(update.id, height, !!update.init);