From 7fd6aaa0a9ffd6f28f3a6bca94df54a04565ae41 Mon Sep 17 00:00:00 2001 From: rebornix Date: Mon, 27 Sep 2021 14:29:50 -0700 Subject: [PATCH] fix #129552 --- .../interactive/browser/interactiveEditor.ts | 9 +++++++-- .../notebook/browser/notebookEditorWidget.ts | 8 ++++++++ .../notebook/browser/view/notebookCellList.ts | 16 ++++++++++++++++ .../browser/view/notebookRenderingCommon.ts | 1 + 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts b/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts index 752662c00c0..a458818688d 100644 --- a/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts +++ b/src/vs/workbench/contrib/interactive/browser/interactiveEditor.ts @@ -22,7 +22,7 @@ import { EditorPane } from 'vs/workbench/browser/parts/editor/editorPane'; import { IEditorOpenContext } from 'vs/workbench/common/editor'; import { getSimpleCodeEditorWidgetOptions, getSimpleEditorOptions } from 'vs/workbench/contrib/codeEditor/browser/simpleEditorOptions'; import { InteractiveEditorInput } from 'vs/workbench/contrib/interactive/browser/interactiveEditorInput'; -import { IActiveNotebookEditorDelegate, ICellViewModel, INotebookEditorOptions } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; +import { CodeCellLayoutChangeEvent, IActiveNotebookEditorDelegate, ICellViewModel, INotebookEditorOptions } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; import { NotebookEditorExtensionsRegistry } from 'vs/workbench/contrib/notebook/browser/notebookEditorExtensions'; import { IBorrowValue, INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/notebookEditorService'; import { cellEditorBackground, NotebookEditorWidget } from 'vs/workbench/contrib/notebook/browser/notebookEditorWidget'; @@ -43,6 +43,7 @@ import { ToolBar } from 'vs/base/browser/ui/toolbar/toolbar'; import { IContextMenuService } from 'vs/platform/contextview/browser/contextView'; import { createActionViewItem, createAndFillInActionBarActions } from 'vs/platform/actions/browser/menuEntryActionViewItem'; import { IAction } from 'vs/base/common/actions'; +import { CodeCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel'; const DECORATION_KEY = 'interactiveInputDecoration'; @@ -399,7 +400,7 @@ export class InteractiveEditor extends EditorPane { * - receive a scroll event (scroll even already happened). If the last cell is at bottom, false, 0, true, state 1 * - height change of the last cell, if state 0, do nothing, if state 1, scroll the last cell fully into view */ - #registerExecutionScrollListener(widget: IActiveNotebookEditorDelegate) { + #registerExecutionScrollListener(widget: NotebookEditorWidget & IActiveNotebookEditorDelegate) { this.#widgetDisposableStore.add(widget.textModel.onWillAddRemoveCells(e => { const lastViewCell = widget.cellAt(widget.getLength() - 1); @@ -449,6 +450,10 @@ export class InteractiveEditor extends EditorPane { return; } + if (this.#lastCell instanceof CodeCellViewModel && (e as CodeCellLayoutChangeEvent).outputHeight === undefined && !this.#notebookWidget.value!.isScrolledToBottom()) { + return; + } + if (this.#state !== ScrollingState.StickyToBottom) { return; } diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts index 44d83fe3538..870c57917c4 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts @@ -84,6 +84,10 @@ export class ListViewInfoAccessor extends Disposable { this.list.scrollTop = scrollTop; } + isScrolledToBottom() { + return this.list.isScrolledToBottom(); + } + scrollToBottom() { this.list.scrollToBottom(); } @@ -1779,6 +1783,10 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD }); } + isScrolledToBottom() { + return this._listViewInfoAccessor.isScrolledToBottom(); + } + scrollToBottom() { this._listViewInfoAccessor.scrollToBottom(); } diff --git a/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts b/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts index 5d5ce2446e8..18c47ea38a6 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/notebookCellList.ts @@ -736,6 +736,22 @@ export class NotebookCellList extends WorkbenchList implements ID this._revealInView(startIndex); } + isScrolledToBottom() { + if (this.length === 0) { + return true; + } + + const last = this.length - 1; + const bottom = this.view.elementHeight(last) + this.view.elementTop(last); + const wrapperBottom = this.getViewScrollTop() + this.view.renderHeight; + + if (bottom <= wrapperBottom) { + return true; + } + + return false; + } + scrollToBottom() { const scrollHeight = this.view.scrollHeight; const scrollTop = this.getViewScrollTop(); diff --git a/src/vs/workbench/contrib/notebook/browser/view/notebookRenderingCommon.ts b/src/vs/workbench/contrib/notebook/browser/view/notebookRenderingCommon.ts index 7f4e414710b..9ce7173a360 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/notebookRenderingCommon.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/notebookRenderingCommon.ts @@ -60,6 +60,7 @@ export interface INotebookCellList { getFocusedElements(): ICellViewModel[]; getSelectedElements(): ICellViewModel[]; revealElementsInView(range: ICellRange): void; + isScrolledToBottom(): boolean; scrollToBottom(): void; revealElementInView(element: ICellViewModel): void; revealElementInViewAtTop(element: ICellViewModel): void;