Enable scrolling outputs by default

This commit is contained in:
Jeremy Tuloup 2021-11-15 21:31:29 +01:00
parent 05470cd626
commit 3b4d899aca

View File

@ -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<void> = {
}
};
/**
* A plugin to enable scrolling for outputs by default
*/
const scrollOutput: JupyterFrontEndPlugin<void> = {
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<any>[] = [
checkpoints,
kernelLogo,
kernelStatus
kernelStatus,
scrollOutput
];
export default plugins;