Skip to content
Open
8 changes: 8 additions & 0 deletions packages/application-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,24 @@ const opener: JupyterFrontEndPlugin<void> = {
): void => {
const { commands, docRegistry } = app;

const ignoredPattern = new RegExp('/tree/(.*)');
const pathSegmentPattern = new RegExp('\\bnotebooks\\b|\\bedit\\b');
const command = 'router:tree';
commands.addCommand(command, {
execute: (args: any) => {
const parsed = args as IRouter.ILocation;
const matches = parsed.path.match(TREE_PATTERN) ?? [];

const [, , path] = matches;
if (!path) {
return;
}

const pathSegments: string[] = parsed.path.split(pathSegmentPattern);
if (pathSegments.length > 1 && pathSegments[0].match(ignoredPattern)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if following a similar logic as in JupyterLab (disposing the command after routing) could help keep things simpler and avoid special cases using patterns?

https://github.com/jupyterlab/jupyterlab/blob/cdca0a20ba84af21922c390c46e086e50120d4cc/packages/application-extension/src/index.tsx#L938-L939

return;
}

app.started.then(async () => {
const file = decodeURIComponent(path);
const urlParams = new URLSearchParams(parsed.search);
Expand Down
5 changes: 4 additions & 1 deletion packages/console-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ const opener: JupyterFrontEndPlugin<void> = {
activate: (app: JupyterFrontEnd, router: IRouter) => {
const { commands } = app;
const consolePattern = new RegExp('/consoles/(.*)');
const ignoreTreePattern = new RegExp('/(tree|notebooks|edit)/(.*)');

const command = 'router:console';
commands.addCommand(command, {
execute: (args: any) => {
const parsed = args as IRouter.ILocation;
const matches = parsed.path.match(consolePattern);
if (!matches) {
const isTreeMatch = parsed.path.match(ignoreTreePattern);

if (isTreeMatch || !matches) {
return;
}
const [, match] = matches;
Expand Down
5 changes: 4 additions & 1 deletion packages/terminal-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ const opener: JupyterFrontEndPlugin<void> = {
) => {
const { commands } = app;
const terminalPattern = new RegExp('/terminals/(.*)');
const ignoreTreePattern = new RegExp('/(tree|notebooks|edit)/(.*)');

const command = 'router:terminal';
commands.addCommand(command, {
execute: (args: any) => {
const parsed = args as IRouter.ILocation;
const matches = parsed.path.match(terminalPattern);
if (!matches) {
const isTreeMatch = parsed.path.match(ignoreTreePattern);

if (isTreeMatch || !matches) {
return;
}
const [, name] = matches;
Expand Down