Skip to content

Commit

Permalink
Fix the ToC on Notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
brichet committed Aug 2, 2022
1 parent 3d1f5b9 commit a6b41a0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
2 changes: 2 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ async function main() {
require('@jupyterlab/apputils-extension').default.filter(({ id }) =>
[
'@jupyterlab/apputils-extension:palette',
'@jupyter/apputils-extension:sanitizer',
'@jupyterlab/apputils-extension:settings',
'@jupyterlab/apputils-extension:state',
'@jupyterlab/apputils-extension:themes',
Expand Down Expand Up @@ -135,6 +136,7 @@ async function main() {
'@jupyterlab/notebook-extension:code-console',
'@jupyterlab/notebook-extension:export',
'@jupyterlab/notebook-extension:factory',
'@jupyterlab/notebook-extension:toc',
'@jupyterlab/notebook-extension:tracker',
'@jupyterlab/notebook-extension:widget-factory'
].includes(id)
Expand Down
5 changes: 2 additions & 3 deletions packages/application-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ const opener: JupyterFrontEndPlugin<void> = {

const command = 'router:tree';
commands.addCommand(command, {
execute: (args: any) => {
execute: async (args: any) => {
const parsed = args as IRouter.ILocation;
const matches = parsed.path.match(TREE_PATTERN) ?? [];
const [, , path] = matches;
Expand All @@ -195,12 +195,11 @@ const opener: JupyterFrontEndPlugin<void> = {

const file = decodeURIComponent(path);
const ext = PathExt.extname(file);
app.restored.then(async () => {
await new Promise(async () => {
// TODO: get factory from file type instead?
if (ext === '.ipynb') {
// TODO: fix upstream?
await settingRegistry?.load('@jupyterlab/notebook-extension:panel');
await Promise.resolve();
docManager.open(file, NOTEBOOK_FACTORY, undefined, {
ref: '_noref'
});
Expand Down
11 changes: 11 additions & 0 deletions packages/application/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export class NotebookApp extends JupyterFrontEnd<INotebookShell> {
this.registerPlugin(plugin);
}
}

this.restored = this.shell.restored
.then(() => undefined)
.catch(() => undefined);

this.restored.then(() => this._formatter.invoke());
}

Expand All @@ -55,6 +60,12 @@ export class NotebookApp extends JupyterFrontEnd<INotebookShell> {
*/
readonly status = new LabStatus(this);

/**
* Promise that resolves when state is first restored, returning layout
* description.
*/
readonly restored: Promise<void>;

/**
* The version of the application.
*/
Expand Down
13 changes: 10 additions & 3 deletions packages/application/src/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { PageConfig } from '@jupyterlab/coreutils';
import { DocumentRegistry } from '@jupyterlab/docregistry';

import { ArrayExt, find, IIterator, iter } from '@lumino/algorithm';
import { Token } from '@lumino/coreutils';
import { PromiseDelegate, Token } from '@lumino/coreutils';
import { Message, MessageLoop, IMessageHandler } from '@lumino/messaging';
import { Debouncer } from '@lumino/polling';
import { ISignal, Signal } from '@lumino/signaling';
Expand Down Expand Up @@ -75,12 +75,10 @@ export class NotebookShell extends Widget implements JupyterFrontEnd.IShell {
} else {
this.layout = this.initLayoutWithoutSidePanels();
}

}

initLayoutWithoutSidePanels(): Layout {
const rootLayout = new BoxLayout();

BoxLayout.setStretch(this._main, 1);

this._spacer = new Widget();
Expand Down Expand Up @@ -211,6 +209,13 @@ export class NotebookShell extends Widget implements JupyterFrontEnd.IShell {
return !(this._rightHandler.isVisible && this.rightPanel.isVisible);
}

/**
* Promise that resolves when main widget is loaded
*/
get restored(): Promise<void> {
return this._mainWidgetLoaded.promise;
}

/**
* Activate a widget in its area.
*/
Expand Down Expand Up @@ -259,6 +264,7 @@ export class NotebookShell extends Widget implements JupyterFrontEnd.IShell {
this._main.addWidget(widget);
this._main.update();
this._currentChanged.emit(void 0);
this._mainWidgetLoaded.resolve();
break;
case 'left':
if (this.sidePanelsVisible()) {
Expand Down Expand Up @@ -410,6 +416,7 @@ export class NotebookShell extends Widget implements JupyterFrontEnd.IShell {
private _spacer: Widget;
private _main: Panel;
private _currentChanged = new Signal<this, void>(this);
private _mainWidgetLoaded = new PromiseDelegate<void>();
}

/**
Expand Down

0 comments on commit a6b41a0

Please sign in to comment.