Merge pull request #54 from jtpio/focus

Implement activateById to fix some focus issues
Jeremy Tuloup 5 years ago committed by GitHub
commit cb38a27f7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -298,12 +298,12 @@ const title: JupyterFrontEndPlugin<void> = {
docManager: IDocumentManager | null,
router: IRouter | null
) => {
// TODO: this signal might not be needed if we assume there is always only
// one notebook in the main area
const widget = new Widget();
widget.id = 'jp-title';
app.shell.add(widget, 'top', { rank: 10 });
// TODO: this signal might not be needed if we assume there is always only
// one notebook in the main area
shell.currentChanged.connect(async () => {
const current = shell.currentWidget;
if (!(current instanceof DocumentWidget)) {
@ -318,23 +318,30 @@ const title: JupyterFrontEndPlugin<void> = {
}
widget.node.onclick = async () => {
const result = await renameDialog(docManager, current.context.path);
if (result) {
const basename = PathExt.basename(result.path);
h.textContent = basename;
if (!router) {
return;
}
const current = router.current;
const matches = current.path.match(TREE_PATTERN) ?? [];
const [, route, path] = matches;
if (!route || !path) {
return;
}
const encoded = encodeURIComponent(result.path);
router.navigate(`/classic/${route}/${encoded}`, {
skipRouting: true
});
// activate the current widget to bring the focus
if (current) {
current.activate();
}
if (!result) {
return;
}
const basename = PathExt.basename(result.path);
h.textContent = basename;
if (!router) {
return;
}
const matches = router.current.path.match(TREE_PATTERN) ?? [];
const [, route, path] = matches;
if (!route || !path) {
return;
}
const encoded = encodeURIComponent(result.path);
router.navigate(`/classic/${route}/${encoded}`, {
skipRouting: true
});
};
});
}

@ -5,7 +5,7 @@ import { JupyterFrontEnd } from '@jupyterlab/application';
import { DocumentRegistry } from '@jupyterlab/docregistry';
import { ArrayExt, IIterator, iter } from '@lumino/algorithm';
import { ArrayExt, find, IIterator, iter } from '@lumino/algorithm';
import { Token } from '@lumino/coreutils';
@ -103,8 +103,14 @@ export class ClassicShell extends Widget implements JupyterFrontEnd.IShell {
return this._menuWrapper;
}
/**
* Activate a widget in its area.
*/
activateById(id: string): void {
// no-op
const widget = find(this.widgets('main'), w => w.id === id);
if (widget) {
widget.activate();
}
}
/**

Loading…
Cancel
Save