Skip to content

Commit a6b41a0

Browse files
committed
Fix the ToC on Notebook
1 parent 3d1f5b9 commit a6b41a0

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

app/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ async function main() {
8383
require('@jupyterlab/apputils-extension').default.filter(({ id }) =>
8484
[
8585
'@jupyterlab/apputils-extension:palette',
86+
'@jupyter/apputils-extension:sanitizer',
8687
'@jupyterlab/apputils-extension:settings',
8788
'@jupyterlab/apputils-extension:state',
8889
'@jupyterlab/apputils-extension:themes',
@@ -135,6 +136,7 @@ async function main() {
135136
'@jupyterlab/notebook-extension:code-console',
136137
'@jupyterlab/notebook-extension:export',
137138
'@jupyterlab/notebook-extension:factory',
139+
'@jupyterlab/notebook-extension:toc',
138140
'@jupyterlab/notebook-extension:tracker',
139141
'@jupyterlab/notebook-extension:widget-factory'
140142
].includes(id)

packages/application-extension/src/index.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ const opener: JupyterFrontEndPlugin<void> = {
185185

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

196196
const file = decodeURIComponent(path);
197197
const ext = PathExt.extname(file);
198-
app.restored.then(async () => {
198+
await new Promise(async () => {
199199
// TODO: get factory from file type instead?
200200
if (ext === '.ipynb') {
201201
// TODO: fix upstream?
202202
await settingRegistry?.load('@jupyterlab/notebook-extension:panel');
203-
await Promise.resolve();
204203
docManager.open(file, NOTEBOOK_FACTORY, undefined, {
205204
ref: '_noref'
206205
});

packages/application/src/app.ts

+11
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ export class NotebookApp extends JupyterFrontEnd<INotebookShell> {
3737
this.registerPlugin(plugin);
3838
}
3939
}
40+
41+
this.restored = this.shell.restored
42+
.then(() => undefined)
43+
.catch(() => undefined);
44+
4045
this.restored.then(() => this._formatter.invoke());
4146
}
4247

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

63+
/**
64+
* Promise that resolves when state is first restored, returning layout
65+
* description.
66+
*/
67+
readonly restored: Promise<void>;
68+
5869
/**
5970
* The version of the application.
6071
*/

packages/application/src/shell.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { PageConfig } from '@jupyterlab/coreutils';
66
import { DocumentRegistry } from '@jupyterlab/docregistry';
77

88
import { ArrayExt, find, IIterator, iter } from '@lumino/algorithm';
9-
import { Token } from '@lumino/coreutils';
9+
import { PromiseDelegate, Token } from '@lumino/coreutils';
1010
import { Message, MessageLoop, IMessageHandler } from '@lumino/messaging';
1111
import { Debouncer } from '@lumino/polling';
1212
import { ISignal, Signal } from '@lumino/signaling';
@@ -75,12 +75,10 @@ export class NotebookShell extends Widget implements JupyterFrontEnd.IShell {
7575
} else {
7676
this.layout = this.initLayoutWithoutSidePanels();
7777
}
78-
7978
}
8079

8180
initLayoutWithoutSidePanels(): Layout {
8281
const rootLayout = new BoxLayout();
83-
8482
BoxLayout.setStretch(this._main, 1);
8583

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

212+
/**
213+
* Promise that resolves when main widget is loaded
214+
*/
215+
get restored(): Promise<void> {
216+
return this._mainWidgetLoaded.promise;
217+
}
218+
214219
/**
215220
* Activate a widget in its area.
216221
*/
@@ -259,6 +264,7 @@ export class NotebookShell extends Widget implements JupyterFrontEnd.IShell {
259264
this._main.addWidget(widget);
260265
this._main.update();
261266
this._currentChanged.emit(void 0);
267+
this._mainWidgetLoaded.resolve();
262268
break;
263269
case 'left':
264270
if (this.sidePanelsVisible()) {
@@ -410,6 +416,7 @@ export class NotebookShell extends Widget implements JupyterFrontEnd.IShell {
410416
private _spacer: Widget;
411417
private _main: Panel;
412418
private _currentChanged = new Signal<this, void>(this);
419+
private _mainWidgetLoaded = new PromiseDelegate<void>();
413420
}
414421

415422
/**

0 commit comments

Comments
 (0)