diff --git a/packages/application-extension/src/index.ts b/packages/application-extension/src/index.ts index b337117ee..c6df1306d 100644 --- a/packages/application-extension/src/index.ts +++ b/packages/application-extension/src/index.ts @@ -298,12 +298,12 @@ const title: JupyterFrontEndPlugin = { 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 = { } 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 + }); }; }); }