Skip to content

Set undoManager in constructor for cells in notebook #321

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

krassowski
Copy link
Collaborator

A fix for jupyterlab/jupyterlab#17247.

Previously an assumption was made that the undo manager can be only instantiated after the cell's ymodel gets inserted into the notebook (more precisely, after it gets added to the _ycells array). This is because doing so before that resulted in an error being raised due to cell.ymodel.doc being null (as the docs is set on ymodel only when it gets inserted into an YArrray with a document).

However, the doc set during insertion is just the notebook's doc and we can access it earlier in the cell's constructor under this._notebook.ydoc; further, the Y.UndoManager has a way to pass a doc explicitly if one cannot rely on extraction from ymodel (which is exactly the case we face).

That assumption dates back to jupyterlab/jupyterlab#13168 (around the same time as the doc parameter was added to yjs in yjs/yjs@6fa8778).

@krassowski krassowski added the bug Something isn't working label Apr 17, 2025
@@ -187,7 +191,7 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
}

/**
* Cell notebook awareness or null if the cell is standalone.
* Cell notebook awareness or null.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unrelated, but I spotted that if the cell is standalone then this._awareness is defined in line 184 (old line 180) so it definitely is not null.

* Defer setting the undo manager as it requires the
* cell to be attached to the notebook Y document.
*/
setUndoManager(): void {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should we remove it as it is not part of the public API defined in api.ts and was only used internally in ynotebook.ts, or should we keep it and deprecate, making it a no-op?

Copy link
Collaborator

Choose a reason for hiding this comment

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

If it's not part of the public API, I'd say we should remove it.

Copy link
Collaborator

@davidbrochart davidbrochart left a comment

Choose a reason for hiding this comment

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

LGTM.

* Defer setting the undo manager as it requires the
* cell to be attached to the notebook Y document.
*/
setUndoManager(): void {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If it's not part of the public API, I'd say we should remove it.

@krassowski krassowski merged commit accc313 into jupyter-server:main Apr 18, 2025
10 of 12 checks passed
@krassowski krassowski deleted the setUndoManagerStraightAway branch April 18, 2025 09:12
@krassowski
Copy link
Collaborator Author

Thank you for the review @davidbrochart! Would you be able to release a new version with this patch? I do not have release rights on this repo.

@davidbrochart
Copy link
Collaborator

I released v3.0.4, sorry for the delay.
I also changed your role to admin in this repository, I don't know if that will allow you to make a release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants