Skip to content

Commit a794e12

Browse files
brichetfoo
authored andcommitted
Fix the ToC on Notebook (and remove remaining comments from rebase)
1 parent b29a925 commit a794e12

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

app/index.js

Lines changed: 2 additions & 0 deletions
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',
@@ -136,6 +137,7 @@ async function main() {
136137
'@jupyterlab/notebook-extension:code-console',
137138
'@jupyterlab/notebook-extension:export',
138139
'@jupyterlab/notebook-extension:factory',
140+
'@jupyterlab/notebook-extension:toc',
139141
'@jupyterlab/notebook-extension:tracker',
140142
'@jupyterlab/notebook-extension:widget-factory'
141143
].includes(id)

packages/application-extension/src/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ const opener: JupyterFrontEndPlugin<void> = {
186186

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

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

packages/application/src/app.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ export class NotebookApp extends JupyterFrontEnd<INotebookShell> {
3434
this.registerPlugin(plugin);
3535
}
3636
}
37+
38+
this.restored = this.shell.restored
39+
.then(() => undefined)
40+
.catch(() => undefined);
41+
3742
this.restored.then(() => this._formatter.invoke());
3843
}
3944

@@ -52,6 +57,12 @@ export class NotebookApp extends JupyterFrontEnd<INotebookShell> {
5257
*/
5358
readonly status = new LabStatus(this);
5459

60+
/**
61+
* Promise that resolves when state is first restored, returning layout
62+
* description.
63+
*/
64+
readonly restored: Promise<void>;
65+
5566
/**
5667
* The version of the application.
5768
*/

packages/application/src/shell.ts

Lines changed: 10 additions & 12 deletions
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 } 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()) {
@@ -382,15 +388,6 @@ export class NotebookShell extends Widget implements JupyterFrontEnd.IShell {
382388
}
383389
}
384390

385-
/**
386-
* Return the list of widgets for the given area.
387-
*
388-
* @param area The area
389-
*/
390-
// widgets(area?: string): IIterator<Widget> {
391-
// return iter(this.widgetsList(area));
392-
// }
393-
394391
/**
395392
* Is a particular area empty (no widgets)?
396393
*
@@ -430,6 +427,7 @@ export class NotebookShell extends Widget implements JupyterFrontEnd.IShell {
430427
private _spacer: Widget;
431428
private _main: Panel;
432429
private _currentChanged = new Signal<this, void>(this);
430+
private _mainWidgetLoaded = new PromiseDelegate<void>();
433431
}
434432

435433
/**

0 commit comments

Comments
 (0)