-
Notifications
You must be signed in to change notification settings - Fork 18
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
Set undoManager
in constructor for cells in notebook
#321
Conversation
@@ -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. |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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.
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. |
I released v3.0.4, sorry for the delay. |
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 tocell.ymodel.doc
beingnull
(as the docs is set onymodel
only when it gets inserted into anYArrray
with a document).However, the
doc
set during insertion is just the notebook'sdoc
and we can access it earlier in the cell's constructor underthis._notebook.ydoc
; further, theY.UndoManager
has a way to pass a doc explicitly if one cannot rely on extraction fromymodel
(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).