Skip to content

Commit 58d8e41

Browse files
authored
Merge pull request #246 from davidbrochart/origin
2 parents b3905b3 + 9a6072a commit 58d8e41

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

javascript/src/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export interface ISharedBase extends IObservableDisposable {
7878
* @param f Transaction to execute
7979
* @param undoable Whether to track the change in the action history or not (default `true`)
8080
*/
81-
transact(f: () => void, undoable?: boolean): void;
81+
transact(f: () => void, undoable?: boolean, origin?: any): void;
8282
}
8383

8484
/**

javascript/src/ycell.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -564,11 +564,11 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
564564
* @param f Transaction to execute
565565
* @param undoable Whether to track the change in the action history or not (default `true`)
566566
*/
567-
transact(f: () => void, undoable = true): void {
567+
transact(f: () => void, undoable = true, origin: any = null): void {
568568
!this.notebook || this.notebook.disableDocumentWideUndoRedo
569569
? this.ymodel.doc == null
570570
? f()
571-
: this.ymodel.doc.transact(f, undoable ? this : null)
571+
: this.ymodel.doc.transact(f, undoable ? this : origin)
572572
: this.notebook.transact(f, undoable);
573573
}
574574

@@ -656,8 +656,13 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
656656
/**
657657
* Handle a change to the ymodel.
658658
*/
659-
private _modelObserver = (events: Y.YEvent<any>[]) => {
660-
this._changed.emit(this.getChanges(events));
659+
private _modelObserver = (
660+
events: Y.YEvent<any>[],
661+
transaction: Y.Transaction
662+
) => {
663+
if (transaction.origin !== 'modeldb') {
664+
this._changed.emit(this.getChanges(events));
665+
}
661666
};
662667

663668
protected _metadataChanged = new Signal<this, IMapChange>(this);
@@ -838,15 +843,20 @@ export class YCodeCell
838843
updateOutputs(
839844
start: number,
840845
end: number,
841-
outputs: Array<nbformat.IOutput> = []
846+
outputs: Array<nbformat.IOutput> = [],
847+
origin: any = null
842848
): void {
843849
const fin =
844850
end < this._youtputs.length ? end - start : this._youtputs.length - start;
845-
this.transact(() => {
846-
this._youtputs.delete(start, fin);
847-
const newOutputs = this.createOutputs(outputs);
848-
this._youtputs.insert(start, newOutputs);
849-
}, false);
851+
this.transact(
852+
() => {
853+
this._youtputs.delete(start, fin);
854+
const newOutputs = this.createOutputs(outputs);
855+
this._youtputs.insert(start, newOutputs);
856+
},
857+
false,
858+
origin
859+
);
850860
}
851861

852862
/**

javascript/src/ydocument.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ export abstract class YDocument<T extends DocumentChange>
170170
* Perform a transaction. While the function f is called, all changes to the shared
171171
* document are bundled into a single event.
172172
*/
173-
transact(f: () => void, undoable = true): void {
174-
this.ydoc.transact(f, undoable ? this : null);
173+
transact(f: () => void, undoable = true, origin: any = null): void {
174+
this.ydoc.transact(f, undoable ? this : origin);
175175
}
176176

177177
/**

0 commit comments

Comments
 (0)