diff --git a/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts b/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts index c3aa3836e7f..c7ef680fd2b 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts @@ -155,7 +155,7 @@ export interface INotebookEditor { /** * Layout the cell with a new height */ - layoutNotebookCell(cell: ICellViewModel, height: number): void; + layoutNotebookCell(cell: ICellViewModel, height: number): Promise; /** * Render the output in webview layer diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts index c82f940b614..4d27b7d0c4a 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditor.ts @@ -564,7 +564,7 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor { //#endregion //#region Cell operations - layoutNotebookCell(cell: ICellViewModel, height: number) { + async layoutNotebookCell(cell: ICellViewModel, height: number): Promise { let relayout = (cell: ICellViewModel, height: number) => { let index = this.notebookViewModel!.getViewCellIndex(cell); if (index >= 0) { @@ -572,9 +572,13 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor { } }; + let r: () => void; DOM.scheduleAtNextAnimationFrame(() => { relayout(cell, height); + r(); }); + + return new Promise(resolve => { r = resolve; }); } async insertNotebookCell(cell: ICellViewModel, type: CellKind, direction: 'above' | 'below', initialText: string = ''): Promise { @@ -589,9 +593,13 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor { newCell.editState = CellEditState.Editing; } + let r: () => void; DOM.scheduleAtNextAnimationFrame(() => { this.list?.revealInCenterIfOutsideViewport(insertIndex); + r(); }); + + return new Promise(resolve => { r = resolve; }); } async deleteNotebookCell(cell: ICellViewModel): Promise { @@ -600,26 +608,30 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor { this.notebookViewModel!.deleteCell(index, true); } - moveCellDown(cell: ICellViewModel): void { + async moveCellDown(cell: ICellViewModel): Promise { const index = this.notebookViewModel!.getViewCellIndex(cell); const newIdx = index + 1; - this.moveCellToIndex(index, newIdx); + return this.moveCellToIndex(index, newIdx); } - moveCellUp(cell: ICellViewModel): void { + async moveCellUp(cell: ICellViewModel): Promise { const index = this.notebookViewModel!.getViewCellIndex(cell); const newIdx = index - 1; - this.moveCellToIndex(index, newIdx); + return this.moveCellToIndex(index, newIdx); } - private moveCellToIndex(index: number, newIdx: number): void { + private async moveCellToIndex(index: number, newIdx: number): Promise { if (!this.notebookViewModel!.moveCellToIdx(index, newIdx, true)) { return; } + let r: () => void; DOM.scheduleAtNextAnimationFrame(() => { this.list?.revealInCenterIfOutsideViewport(index + 1); + r(); }); + + return new Promise(resolve => { r = resolve; }); } editNotebookCell(cell: CellViewModel): void { diff --git a/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts b/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts index 53f4be826a2..f79674c0484 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts @@ -306,6 +306,10 @@ export class NotebookCellList extends WorkbenchList implements ID } private _revealInternal(index: number, ignoreIfInsideViewport: boolean, revealPosition: CellRevealPosition) { + if (index >= this.view.length) { + return; + } + const scrollTop = this.view.getScrollTop(); const wrapperBottom = scrollTop + this.view.renderHeight; const elementTop = this.view.elementTop(index);