Reload shows the first tab when the active tab is not restored
Description
On a page reload, when the tab that was active is not (yet) restored, the tab bar shows the first tab of the main area. A Launcher is such a tab, and so is a tab that an extension adds without a restorer. The status bar and the file browser show the file of another tab.
Reproduce
- Open a notebook and then a Python file from the file browser, for example
Untitled.ipynbandhelper.py. - Close the Launcher tab.
- Select File → New Launcher. The tabs are
Untitled.ipynb,helper.pyandLauncher, withLauncheractive. - Reload the page.
The tab bar shows Untitled.ipynb, the first tab. The status bar shows Ln 1, Col 1, Spaces: 4 and helper.py, and the file browser selects helper.py. shell.currentWidget is helper.py, although its tab is not selected.
Expected behavior
helper.py, the tab before the Launcher, is shown and is the current widget.
Possible solution
The layout restorer saves currentIndex counted among all tabs, but it saves only the tabs that have a restore name:
On restore, an index past the end of the saved tabs resets to 0:
When the current tab has no restore name, the restorer does not save a current widget, and restoreLayout then does not activate a tab:
The layout restorer counts the current index among the tabs that it saves, and saves the nearest tab with a restore name as the current widget. When a saved tab does not come back, the restore selects the nearest tab that does.
Context
- Operating System and version: Linux
- Browser and version: Chromium 149
- JupyterLab version: 4.6.4 and 4.7.0a2
Source: jupyterlab/jupyterlab