notebook icon indicating copy to clipboard operation
notebook copied to clipboard

Add the layout restorer

Open brichet opened this issue 2 months ago • 4 comments

Adds the layout restorer, to restore the state of the side/down panels. It includes the current widgets opened in each panel, and the size of the panels.

record-2025-10-17_20.16.35.webm

Fixes #6990

User facing change

  • save and restore the layout, only for the Notebook view, since it is the only one with side and bottom panels
  • use only one workspace (unlike Jupyterlab), to avoid confusion. This means that changing the layout in one Notebook will affect the layout of other Notebook if they are reloaded. This workspace file is save in the jupyterlab workspace directory (.jupyter/lab/workspaces) and is named nb-default.

Code changes

  • add the RestoreLayout and SaveLayout function to the shell, which uses some dedicated function to "dehydrate" and "rehydrate" the shell
  • adds 2 plugins:
    • '@jupyter-notebook/application-extension:layout', which handle the shell layout restoration
    • '@jupyter-notebook/apputils-extension:state', which was previously activated from jupyterlab. Providing our own IStateDB allow to avoid some side effect, that the tab title update (which does not work correctly in Notebook, see https://github.com/jupyter/notebook/pull/7747#issuecomment-3425653114)

brichet avatar Oct 17 '25 18:10 brichet

Binder :point_left: Launch a Binder on branch brichet/notebook/restorer

github-actions[bot] avatar Oct 17 '25 18:10 github-actions[bot]

EDIT this error has been fixed

There is a conflict on the title of the browser tab with this PR.

BEFORE THE PR

record-2025-10-21_11.29.54.webm

AFTER THE PR

record-2025-10-21_11.30.28.webm

The tab title is not updated correctly anymore, probably because of https://github.com/jupyterlab/jupyterlab/blob/21f9c73298d7a450dba9927d404c87aae3011f7a/packages/apputils-extension/src/index.ts#L462-L469. The code above wasn't called before this PR because there was no window resolver. It is required in this PR to allow saving the layout.

Maybe we should provide the IStateDB token in Notebook too.

brichet avatar Oct 21 '25 09:10 brichet

Maybe we should provide the IStateDB token in Notebook too.

Added in https://github.com/jupyter/notebook/pull/7747/commits/c1b056e3930efed62c9852be078c1704be6ffec0

brichet avatar Oct 21 '25 13:10 brichet

I converted it to draft to explore layout restoration on other views than Notebook, and workspace reset in the UI.

brichet avatar Oct 24 '25 14:10 brichet