Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
Opt-out from auto scroll outputs via the settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpio committed Dec 31, 2021
1 parent b67bba0 commit 84df24d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/application-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { DocumentWidget } from '@jupyterlab/docregistry';

import { IMainMenu } from '@jupyterlab/mainmenu';

import { ISettingRegistry } from '@jupyterlab/settingregistry';

import { ITranslator } from '@jupyterlab/translation';

import { RetroApp, RetroShell, IRetroShell } from '@retrolab/application';
Expand All @@ -38,7 +40,6 @@ import { PromiseDelegate } from '@lumino/coreutils';
import { DisposableDelegate, DisposableSet } from '@lumino/disposable';

import { Widget } from '@lumino/widgets';
import { ISettingRegistry } from '@jupyterlab/settingregistry';

/**
* The default notebook factory.
Expand Down
4 changes: 3 additions & 1 deletion packages/notebook-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@jupyterlab/cells": "^3.2.5",
"@jupyterlab/docmanager": "^3.2.5",
"@jupyterlab/notebook": "^3.2.5",
"@jupyterlab/settingregistry": "^3.2.5",
"@jupyterlab/translation": "^3.2.5",
"@lumino/polling": "^1.6.0",
"@lumino/widgets": "^1.23.0",
Expand All @@ -57,7 +58,8 @@
"access": "public"
},
"jupyterlab": {
"extension": true
"extension": true,
"schemaDir": "schema"
},
"styleModule": "style/index.js"
}
16 changes: 16 additions & 0 deletions packages/notebook-extension/schema/scroll-output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"jupyter.lab.setting-icon": "retro-ui-components:retroSun",
"jupyter.lab.setting-icon-label": "RetroLab Notebook",
"title": "RetroLab Notebook",
"description": "RetroLab Notebook settings",
"properties": {
"autoScrollOutputs": {
"type": "boolean",
"title": "Auto Scroll Outputs",
"description": "Whether to auto scroll the output area when the outputs become too long",
"default": true
}
},
"additionalProperties": false,
"type": "object"
}
33 changes: 32 additions & 1 deletion packages/notebook-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { IDocumentManager } from '@jupyterlab/docmanager';

import { NotebookPanel, INotebookTracker } from '@jupyterlab/notebook';

import { ISettingRegistry } from '@jupyterlab/settingregistry';

import { ITranslator } from '@jupyterlab/translation';

import { IRetroShell } from '@retrolab/application';
Expand Down Expand Up @@ -230,11 +232,21 @@ const scrollOutput: JupyterFrontEndPlugin<void> = {
id: '@retrolab/notebook-extension:scroll-output',
autoStart: true,
requires: [INotebookTracker],
activate: async (app: JupyterFrontEnd, tracker: INotebookTracker) => {
optional: [ISettingRegistry],
activate: async (
app: JupyterFrontEnd,
tracker: INotebookTracker,
settingRegistry: ISettingRegistry | null
) => {
const autoScrollThreshold = 100;
let autoScrollOutputs = true;

// decide whether to scroll the output of the cell based on some heuristics
const autoScroll = (cell: CodeCell) => {
if (!autoScrollOutputs) {
// bail if disabled via the settings
return;
}
const { outputArea } = cell;
// respect cells with an explicit scrolled state
const scrolled = cell.model.metadata.get('scrolled');
Expand Down Expand Up @@ -279,6 +291,25 @@ const scrollOutput: JupyterFrontEndPlugin<void> = {
});
});
});

if (settingRegistry) {
const loadSettings = settingRegistry.load(scrollOutput.id);
const updateSettings = (settings: ISettingRegistry.ISettings): void => {
autoScrollOutputs = settings.get('autoScrollOutputs')
.composite as boolean;
};

Promise.all([loadSettings, app.restored])
.then(([settings]) => {
updateSettings(settings);
settings.changed.connect(settings => {
updateSettings(settings);
});
})
.catch((reason: Error) => {
console.error(reason.message);
});
}
}
};

Expand Down

0 comments on commit 84df24d

Please sign in to comment.