-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,8 +171,12 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata> | |
this._undoManager = null; | ||
if (options.notebook) { | ||
this._notebook = options.notebook as YNotebook; | ||
// We cannot create a undo manager with the cell not yet attached in the notebook | ||
// so we defer that to the notebook insertCell method | ||
if (this._notebook.disableDocumentWideUndoRedo) { | ||
this._undoManager = new Y.UndoManager([this.ymodel], { | ||
trackedOrigins: new Set([this]), | ||
doc: this._notebook.ydoc | ||
}); | ||
} | ||
} else { | ||
// Standalone cell | ||
const doc = new Y.Doc(); | ||
|
@@ -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. | ||
*/ | ||
get awareness(): Awareness | null { | ||
return this._awareness ?? this.notebook?.awareness ?? null; | ||
|
@@ -288,22 +292,6 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata> | |
: this.notebook.undoManager; | ||
} | ||
|
||
/** | ||
* 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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
if (this._undoManager) { | ||
throw new Error('The cell undo manager is already set.'); | ||
} | ||
|
||
if (this._notebook && this._notebook.disableDocumentWideUndoRedo) { | ||
this._undoManager = new Y.UndoManager([this.ymodel], { | ||
trackedOrigins: new Set([this]) | ||
}); | ||
} | ||
} | ||
|
||
readonly ymodel: Y.Map<any>; | ||
|
||
get ysource(): Y.Text { | ||
|
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 notnull
.