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

Commit

Permalink
Merge pull request #296 from jweill-aws/shorter-title
Browse files Browse the repository at this point in the history
Strip .ipynb extension for display in header and tab title
  • Loading branch information
jtpio authored Dec 2, 2021
2 parents 4fd58de + f5f11b4 commit 49b9ae3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
15 changes: 11 additions & 4 deletions packages/application-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ const EDITOR_FACTORY = 'Editor';
*/
const TREE_PATTERN = new RegExp('/(notebooks|edit)/(.*)');

/**
* A regular expression to suppress the file extension from display for .ipynb files.
*/
const STRIP_IPYNB = /\.ipynb$/;

/**
* The command IDs used by the application plugin.
*/
Expand Down Expand Up @@ -383,15 +388,16 @@ const tabTitle: JupyterFrontEndPlugin<void> = {
const title =
current.sessionContext.path || current.sessionContext.name;
const basename = PathExt.basename(title);
document.title = basename;
// Strip the ".ipynb" suffix from filenames for display in tab titles.
document.title = basename.replace(STRIP_IPYNB, '');
};
current.sessionContext.sessionChanged.connect(update);
update();
return;
} else if (current instanceof DocumentWidget) {
const update = () => {
const basename = PathExt.basename(current.context.path);
document.title = basename;
document.title = basename.replace(STRIP_IPYNB, '');
};
current.context.pathChanged.connect(update);
update();
Expand Down Expand Up @@ -435,7 +441,7 @@ const title: JupyterFrontEndPlugin<void> = {
}

const h = document.createElement('h1');
h.textContent = current.title.label;
h.textContent = current.title.label.replace(STRIP_IPYNB, '');
widget.node.appendChild(h);
widget.node.style.marginLeft = '10px';
if (!docManager) {
Expand Down Expand Up @@ -468,7 +474,8 @@ const title: JupyterFrontEndPlugin<void> = {

const newPath = current.context.path ?? result.path;
const basename = PathExt.basename(newPath);
h.textContent = basename;

h.textContent = basename.replace(STRIP_IPYNB, '');
if (!router) {
return;
}
Expand Down
7 changes: 4 additions & 3 deletions ui-tests/test/notebook.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ test.describe('Notebook', () => {
const notebook = `${tmpPath}/${NOTEBOOK}`;
await page.goto(`notebooks/${notebook}`);

// Click on the title
await page.click('text="example.ipynb"');
// Click on the title (with .ipynb extension stripped)
await page.click('text="example"');

// Rename in the input dialog
const newName = 'test.ipynb';
const newNameStripped = 'test';
await page.fill(
`//div[normalize-space(.)='File Path${notebook}New Name']/input`,
newName
Expand All @@ -52,6 +53,6 @@ test.describe('Notebook', () => {

// Check the URL contains the new name
const url = page.url();
expect(url).toContain(newName);
expect(url).toContain(newNameStripped);
});
});

0 comments on commit 49b9ae3

Please sign in to comment.