Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add the layout restorer#7747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
brichet wants to merge18 commits intojupyter:main
base:main
Choose a base branch
Loading
frombrichet:restorer
Draft

Conversation

@brichet
Copy link
Collaborator

@brichetbrichet commentedOct 17, 2025
edited
Loading

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 namednb-default.

Code changes

  • add theRestoreLayout andSaveLayout 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 ownIStateDB allow to avoid some side effect, that the tab title update (which does not work correctly in Notebook, seeAdd the layout restorer #7747 (comment))

@github-actions
Copy link
Contributor

Binder 👈 Launch a Binder on branchbrichet/notebook/restorer

@brichet
Copy link
CollaboratorAuthor

brichet commentedOct 21, 2025
edited
Loading

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 ofhttps://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 theIStateDB token in Notebook too.

@brichet
Copy link
CollaboratorAuthor

Maybe we should provide theIStateDB token in Notebook too.

Added inc1b056e

@brichetbrichet marked this pull request as ready for reviewOctober 21, 2025 13:28
@jtpiojtpio added this to the7.5.0 milestoneOct 22, 2025
@jtpiojtpio self-requested a reviewOctober 23, 2025 11:49
Copy link
Member

@jtpiojtpio left a comment

Choose a reason for hiding this comment

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

Many thanks@brichet for working on this!

Just did a first pass on the diff without testing locally for now, and overall the changes look good 👍

Left a couple of small comments before checking it locally.

/**
* The default layout restorer provider.
*/
constlayoutRestorer:JupyterFrontEndPlugin<ILayoutRestorer|null>={
Copy link
Member

Choose a reason for hiding this comment

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

Since the left and right panels can also be opened on other pages, maybe this plugin should always provide aLayoutRestorer?

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

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

I though only the Notebook has side panel, but the tree view also have one indeed. And the header is also expandable for all the view.
To avoid confusion, we'll probably need a workspace file for each view (tree, notebook, console, terminal, file), because each view has its own panels.

Currently the workspace filename is set tonb-default in thestate plugin, but we can probably have a dedicated one according to the URL, or the main widget in the shell.

Copy link
Member

Choose a reason for hiding this comment

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

Right, we could look into that separately, and only support the notebook page for now.

brichet reacted with thumbs up emoji
Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

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

There is now one workspace file per view (notebooks,tree, ...), so we can restore the layout for each view.

I tried to change the workspaces directory in the backend to clarify, and have a dedicated directory for Notebook application, without success so far.

I couldn't make it work by replacing

def_default_workspaces_dir(self)->str:
returnt.cast(str,get_workspaces_dir())

with

@default("workspaces_dir")def_default_workspaces_dir(self)->str:workspaces_dir=Path(jupyter_data_dir())/"workspaces"/"notebook_app"workspaces_dir.mkdir(parents=True,exist_ok=True)returnt.cast(str,str(workspaces_dir))

},
});

commands.addCommand(CommandIDs.resetOnLoad,{
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 this command should be exposed somewhere in the UI? Like in JupyterLab under the Workspaces menu.

Users would then have a way to reset the UI to the defaults and clean things up.

It could be part of the command palette or the menu, or both.

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

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

yes, sounds good. It could be in thefile menu, like in lab.

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

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

Actually we should probably create another command (reset) to expose it to the UI. This one checks the URL to find areset in the query parameters.

@brichetbrichet marked this pull request as draftOctober 24, 2025 14:38
@brichet
Copy link
CollaboratorAuthor

brichet commentedOct 24, 2025
edited
Loading

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

jtpio reacted with thumbs up emoji

Comment on lines 8 to 13
asyncrestore(
tracker:WidgetTracker,
options:IRestorer.IOptions<Widget>
):Promise<any>{
// no-op as we don't want to restore widgets, only the layout.
}
Copy link
CollaboratorAuthor

@brichetbrichetOct 27, 2025
edited
Loading

Choose a reason for hiding this comment

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

It looks like this prevents the down area to be restored, at least the log panel.
Overriding the restore function is required AFAIK, to prevent the main area widget to be tracked, and therefore to be restored. Otherwise, loading the page calls a reload of the page (in a new tab) and this can be infinite, because it tries to restore the main area widget.

record-2025-10-27_11.50.22.webm

Not sure how we could handle it yet.

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

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

I added7137789 as a workaround. The idea is to override theStateDB.save to avoid saving the document widget in the workspace.

I don't really like this solution, it is more as a POC, we should probably revert it and handle it upstream in Jupyterlab.
Any thought@jtpio ?

@jtpiojtpio modified the milestones:7.5.0,7.6.0Nov 18, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@jtpiojtpiojtpio left review comments

Assignees

@brichetbrichet

Projects

None yet

Milestone

7.6.0

Development

Successfully merging this pull request may close these issues.

JN 7.0. → Remembering layout of View panels upon saving and reopening a notebook

2 participants

@brichet@jtpio

[8]ページ先頭

©2009-2025 Movatter.jp