Skip to content

Commit

Permalink
Fix #93600. Make notebook editor layout/insert/delete actions async.
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornix committed Mar 27, 2020
1 parent a1f7a1a commit 053ee8e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Expand Up @@ -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<void>;

/**
* Render the output in webview layer
Expand Down
24 changes: 18 additions & 6 deletions src/vs/workbench/contrib/notebook/browser/notebookEditor.ts
Expand Up @@ -564,17 +564,21 @@ export class NotebookEditor extends BaseEditor implements INotebookEditor {
//#endregion

//#region Cell operations
layoutNotebookCell(cell: ICellViewModel, height: number) {
async layoutNotebookCell(cell: ICellViewModel, height: number): Promise<void> {
let relayout = (cell: ICellViewModel, height: number) => {
let index = this.notebookViewModel!.getViewCellIndex(cell);
if (index >= 0) {
this.list?.updateElementHeight(index, height);
}
};

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<void> {
Expand All @@ -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<void> {
Expand All @@ -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<void> {
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<void> {
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<void> {
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 {
Expand Down
Expand Up @@ -306,6 +306,10 @@ export class NotebookCellList extends WorkbenchList<CellViewModel> 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);
Expand Down

0 comments on commit 053ee8e

Please sign in to comment.