Skip to content
This repository was archived by the owner on Feb 16, 2023. It is now read-only.

Commit f5f11b4

Browse files
committed
Strips .ipynb suffix from tab title
1 parent 11b126c commit f5f11b4

File tree

1 file changed

+10
-7
lines changed
  • packages/application-extension/src

1 file changed

+10
-7
lines changed

packages/application-extension/src/index.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ const EDITOR_FACTORY = 'Editor';
5555
*/
5656
const TREE_PATTERN = new RegExp('/(notebooks|edit)/(.*)');
5757

58+
/**
59+
* A regular expression to suppress the file extension from display for .ipynb files.
60+
*/
61+
const STRIP_IPYNB = /\.ipynb$/;
62+
5863
/**
5964
* The command IDs used by the application plugin.
6065
*/
@@ -383,15 +388,16 @@ const tabTitle: JupyterFrontEndPlugin<void> = {
383388
const title =
384389
current.sessionContext.path || current.sessionContext.name;
385390
const basename = PathExt.basename(title);
386-
document.title = basename;
391+
// Strip the ".ipynb" suffix from filenames for display in tab titles.
392+
document.title = basename.replace(STRIP_IPYNB, '');
387393
};
388394
current.sessionContext.sessionChanged.connect(update);
389395
update();
390396
return;
391397
} else if (current instanceof DocumentWidget) {
392398
const update = () => {
393399
const basename = PathExt.basename(current.context.path);
394-
document.title = basename;
400+
document.title = basename.replace(STRIP_IPYNB, '');
395401
};
396402
current.context.pathChanged.connect(update);
397403
update();
@@ -434,11 +440,8 @@ const title: JupyterFrontEndPlugin<void> = {
434440
return;
435441
}
436442

437-
// Don't show the file extension for .ipynb files.
438-
const stripIpynb = /\.ipynb$/;
439-
440443
const h = document.createElement('h1');
441-
h.textContent = current.title.label.replace(stripIpynb, '');
444+
h.textContent = current.title.label.replace(STRIP_IPYNB, '');
442445
widget.node.appendChild(h);
443446
widget.node.style.marginLeft = '10px';
444447
if (!docManager) {
@@ -472,7 +475,7 @@ const title: JupyterFrontEndPlugin<void> = {
472475
const newPath = current.context.path ?? result.path;
473476
const basename = PathExt.basename(newPath);
474477

475-
h.textContent = basename.replace(stripIpynb, '');
478+
h.textContent = basename.replace(STRIP_IPYNB, '');
476479
if (!router) {
477480
return;
478481
}

0 commit comments

Comments
 (0)