From 3b4d899aca1d01ac3531faf99ec1f6d5c816ad82 Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Mon, 15 Nov 2021 21:31:29 +0100 Subject: [PATCH] Enable scrolling outputs by default --- packages/notebook-extension/src/index.ts | 32 ++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/packages/notebook-extension/src/index.ts b/packages/notebook-extension/src/index.ts index 5ea0e39ce..c542f6dff 100644 --- a/packages/notebook-extension/src/index.ts +++ b/packages/notebook-extension/src/index.ts @@ -8,11 +8,13 @@ import { import { ISessionContext, DOMUtils } from '@jupyterlab/apputils'; +import { CodeCell } from '@jupyterlab/cells'; + import { Text, Time } from '@jupyterlab/coreutils'; import { IDocumentManager } from '@jupyterlab/docmanager'; -import { NotebookPanel } from '@jupyterlab/notebook'; +import { NotebookPanel, INotebookTracker } from '@jupyterlab/notebook'; import { ITranslator } from '@jupyterlab/translation'; @@ -214,13 +216,39 @@ const kernelStatus: JupyterFrontEndPlugin = { } }; +/** + * A plugin to enable scrolling for outputs by default + */ +const scrollOutput: JupyterFrontEndPlugin = { + id: '@retrolab/notebook-extension:scroll-output', + autoStart: true, + requires: [INotebookTracker], + activate: async (app: JupyterFrontEnd, tracker: INotebookTracker) => { + tracker.widgetAdded.connect((sender, notebook) => { + notebook.model?.cells.changed.connect((sender, changed) => { + // process new cells only + if (!(changed.type === 'add')) { + return; + } + const [cellModel] = changed.newValues; + notebook.content.widgets.forEach(cell => { + if (cell.model.id === cellModel.id && cell.model.type === 'code') { + (cell as CodeCell).outputsScrolled = true; + } + }); + }); + }); + } +}; + /** * Export the plugins as default. */ const plugins: JupyterFrontEndPlugin[] = [ checkpoints, kernelLogo, - kernelStatus + kernelStatus, + scrollOutput ]; export default plugins;