Skip to content

Commit

Permalink
Move _applyDelta to the subclass (the base class doesn't use it).
Browse files Browse the repository at this point in the history
  • Loading branch information
jorendorff committed Apr 9, 2016
1 parent 911ee55 commit 7329011
Showing 1 changed file with 47 additions and 47 deletions.
94 changes: 47 additions & 47 deletions lib/rga.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,51 +251,6 @@ RGA.prototype = {
}
},

// Convenience method to apply a patch. The structure of `delta` is the same
// as a Quill delta, just because it was a JSON patch format I knew about --
// RGA doesn't actually use any Quill code.
_applyDelta: function (delta) {
var source = this.downstream;
var lastNode = this.left, node = lastNode.next;
var ops = delta.ops;
for (var i = 0; i < ops.length; i++) {
var op = ops[i];
//this._log("* applying", op);
if ("retain" in op) {
for (var j = 0; j < op.retain;) {
if (!node.removed) {
lastNode = node;
j++;
}
node = node.next;
}
} else if ("delete" in op) {
for (var j = 0; j < op.delete;) {
var next = node.next;
if (!node.removed) {
lastNode = node;
j++;
//this._log(" - removing character:", node.atom);
this._downstream(source, {type: "remove", t: node.timestamp});
}
node = next;
}
} else if ("insert" in op) {
var t = lastNode.timestamp;
var str = op.insert;
for (var j = 0; j < str.length; j++) {
//this._log(" - inserting character:", str[j]);
var tnext = this._timestamp();
var next = {atom: str[j], timestamp: tnext};
this._downstream(source, {type: "addRight", t: t, w: next});
t = tnext;
}
lastNode = this._index.get(t);
node = lastNode.next;
}
}
},

timestampToIndex: function (t) {
var offset = -1;
for (var node = this.left; node.timestamp !== t; node = node.next) {
Expand Down Expand Up @@ -339,8 +294,8 @@ RGA.tieToSocket = function tieToSocket(a, s) {
});
};

// Return a Quill patch to turn the string s0 into s1.
// (Helper function used by RGA.tieToAceEditor().)
// Return a delta to turn the string s0 into s1.
// (Helper function used by RGA.AceEditorRGA#_takeUserEdits.)
RGA.diff = function diff(s0, s1) {
//console.log("diffing", {a: s0, b: s1});

Expand Down Expand Up @@ -468,6 +423,51 @@ Object.assign(RGA.AceEditorRGA.prototype, {
}
},

// Convenience method to apply a patch. The structure of `delta` is the same
// as a Quill delta, just because it was a JSON patch format I knew about --
// RGA doesn't actually use any Quill code.
_applyDelta: function (delta) {
var source = this.downstream;
var lastNode = this.left, node = lastNode.next;
var ops = delta.ops;
for (var i = 0; i < ops.length; i++) {
var op = ops[i];
//this._log("* applying", op);
if ("retain" in op) {
for (var j = 0; j < op.retain;) {
if (!node.removed) {
lastNode = node;
j++;
}
node = node.next;
}
} else if ("delete" in op) {
for (var j = 0; j < op.delete;) {
var next = node.next;
if (!node.removed) {
lastNode = node;
j++;
//this._log(" - removing character:", node.atom);
this._downstream(source, {type: "remove", t: node.timestamp});
}
node = next;
}
} else if ("insert" in op) {
var t = lastNode.timestamp;
var str = op.insert;
for (var j = 0; j < str.length; j++) {
//this._log(" - inserting character:", str[j]);
var tnext = this._timestamp();
var next = {atom: str[j], timestamp: tnext};
this._downstream(source, {type: "addRight", t: t, w: next});
t = tnext;
}
lastNode = this._index.get(t);
node = lastNode.next;
}
}
},

_takeUserEdits: function () {
var currentText = this.editor.getValue();
//this._log("_takeUserEdits: <" + currentText + "> <" + this._lastText + ">");
Expand Down

0 comments on commit 7329011

Please sign in to comment.