diff --git a/javascript/src/api.ts b/javascript/src/api.ts index 68bc083..a20b301 100644 --- a/javascript/src/api.ts +++ b/javascript/src/api.ts @@ -78,7 +78,7 @@ export interface ISharedBase extends IObservableDisposable { * @param f Transaction to execute * @param undoable Whether to track the change in the action history or not (default `true`) */ - transact(f: () => void, undoable?: boolean): void; + transact(f: () => void, undoable?: boolean, origin?: any): void; } /** diff --git a/javascript/src/ycell.ts b/javascript/src/ycell.ts index 25f4667..16ebd69 100644 --- a/javascript/src/ycell.ts +++ b/javascript/src/ycell.ts @@ -564,11 +564,11 @@ export class YBaseCell * @param f Transaction to execute * @param undoable Whether to track the change in the action history or not (default `true`) */ - transact(f: () => void, undoable = true): void { + transact(f: () => void, undoable = true, origin: any = null): void { !this.notebook || this.notebook.disableDocumentWideUndoRedo ? this.ymodel.doc == null ? f() - : this.ymodel.doc.transact(f, undoable ? this : null) + : this.ymodel.doc.transact(f, undoable ? this : origin) : this.notebook.transact(f, undoable); } @@ -656,8 +656,10 @@ export class YBaseCell /** * Handle a change to the ymodel. */ - private _modelObserver = (events: Y.YEvent[]) => { - this._changed.emit(this.getChanges(events)); + private _modelObserver = (events: Y.YEvent[], transaction: Y.Transaction) => { + if (transaction.origin !== 'modeldb') { + this._changed.emit(this.getChanges(events)); + } }; protected _metadataChanged = new Signal(this); @@ -838,7 +840,8 @@ export class YCodeCell updateOutputs( start: number, end: number, - outputs: Array = [] + outputs: Array = [], + origin: any = null ): void { const fin = end < this._youtputs.length ? end - start : this._youtputs.length - start; @@ -846,7 +849,7 @@ export class YCodeCell this._youtputs.delete(start, fin); const newOutputs = this.createOutputs(outputs); this._youtputs.insert(start, newOutputs); - }, false); + }, false, origin); } /** diff --git a/javascript/src/ydocument.ts b/javascript/src/ydocument.ts index c923c12..96a3fae 100644 --- a/javascript/src/ydocument.ts +++ b/javascript/src/ydocument.ts @@ -170,8 +170,8 @@ export abstract class YDocument * Perform a transaction. While the function f is called, all changes to the shared * document are bundled into a single event. */ - transact(f: () => void, undoable = true): void { - this.ydoc.transact(f, undoable ? this : null); + transact(f: () => void, undoable = true, origin: any = null): void { + this.ydoc.transact(f, undoable ? this : origin); } /**