From 6d173339fcadcd881b5f978c0062f114bf2a92d2 Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Tue, 15 Dec 2020 10:12:57 +0100 Subject: [PATCH 1/3] Handle spaces in file names --- packages/application-extension/src/index.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/application-extension/src/index.ts b/packages/application-extension/src/index.ts index 18c12a1ab..5e8a94923 100644 --- a/packages/application-extension/src/index.ts +++ b/packages/application-extension/src/index.ts @@ -119,11 +119,12 @@ const opener: JupyterFrontEndPlugin = { return; } - const [, , file] = matches; - if (!file) { + const [, , path] = matches; + if (!path) { return; } + const file = decodeURIComponent(path); const ext = PathExt.extname(file); app.restored.then(() => { // TODO: get factory from file type instead? @@ -319,7 +320,8 @@ const title: JupyterFrontEndPlugin = { h.textContent = result.path; if (router) { // TODO: better handle this - router.navigate(`/classic/notebooks/${result.path}`, { + const encoded = encodeURIComponent(result.path); + router.navigate(`/classic/notebooks/${encoded}`, { skipRouting: true }); } From 8a21ef105ea9698430c37ee63445a4f0b2921de3 Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Tue, 15 Dec 2020 10:19:16 +0100 Subject: [PATCH 2/3] Show basename in the title indicator --- packages/application-extension/src/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/application-extension/src/index.ts b/packages/application-extension/src/index.ts index 5e8a94923..95d201466 100644 --- a/packages/application-extension/src/index.ts +++ b/packages/application-extension/src/index.ts @@ -317,7 +317,8 @@ const title: JupyterFrontEndPlugin = { widget.node.onclick = async () => { const result = await renameDialog(docManager, current.context.path); if (result) { - h.textContent = result.path; + const basename = PathExt.basename(result.path); + h.textContent = basename; if (router) { // TODO: better handle this const encoded = encodeURIComponent(result.path); From b63d204da313831a4998ed548086cdbc3bc0bcd2 Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Tue, 15 Dec 2020 10:52:35 +0100 Subject: [PATCH 3/3] Better handle renaming files --- packages/application-extension/src/index.ts | 51 ++++++++++++--------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/packages/application-extension/src/index.ts b/packages/application-extension/src/index.ts index 95d201466..b337117ee 100644 --- a/packages/application-extension/src/index.ts +++ b/packages/application-extension/src/index.ts @@ -45,6 +45,11 @@ const NOTEBOOK_FACTORY = 'Notebook'; */ const EDITOR_FACTORY = 'Editor'; +/** + * A regular expression to match path to notebooks and documents + */ +const TREE_PATTERN = new RegExp('/(notebooks|edit)/(.*)'); + /** * The command IDs used by the application plugin. */ @@ -108,17 +113,12 @@ const opener: JupyterFrontEndPlugin = { docManager: IDocumentManager ): void => { const { commands } = app; - const treePattern = new RegExp('/(notebooks|edit)/(.*)'); const command = 'router:tree'; commands.addCommand(command, { execute: (args: any) => { const parsed = args as IRouter.ILocation; - const matches = parsed.path.match(treePattern); - if (!matches) { - return; - } - + const matches = parsed.path.match(TREE_PATTERN) ?? []; const [, , path] = matches; if (!path) { return; @@ -141,7 +141,7 @@ const opener: JupyterFrontEndPlugin = { } }); - router.register({ command, pattern: treePattern }); + router.register({ command, pattern: TREE_PATTERN }); } }; @@ -313,22 +313,29 @@ const title: JupyterFrontEndPlugin = { h.textContent = current.title.label; widget.node.appendChild(h); widget.node.style.marginLeft = '10px'; - if (docManager) { - 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) { - // TODO: better handle this - const encoded = encodeURIComponent(result.path); - router.navigate(`/classic/notebooks/${encoded}`, { - skipRouting: true - }); - } - } - }; + if (!docManager) { + return; } + 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 + }); + } + }; }); } };