- if (common) {
- var ks = this.computeKeysets(left, right);
- for (idx in ks[0]) {
- okey = ks[0][idx];
- if (left[okey] != right[okey]) {
- out.push([key.concat([okey]), right[okey]]);
- }
- }
- for (idx in ks[1]) {
- okey = ks[1][idx];
- out.push([key.concat([okey])]);
- }
- for (idx in ks[2]) {
- okey = ks[2][idx];
- out.push([key.concat([okey]), right[okey]]);
- }
- return out
- }
- else if ( ! this.isStrictlyEqual(left,right)) {
- return [[key, right]]
- }
- else {
- return []
- }
+ // First we divide the stanzas using splitDeletions():
+ var split_thing = this.splitDeletions(diff);
+ // Then we sort modifications in ascending order of last key:
+ split_thing[0].sort(
+ function(a, b) {return a[0].slice(-1)[0] - b[0].slice(-1)[0];}
+ );
+ // And deletions in descending order of last key:
+ split_thing[1].sort(
+ function(a, b) {return b[0].slice(-1)[0] - a[0].slice(-1)[0];}
+ );
+ // And recombine:
+ return split_thing[0].concat(split_thing[1]);
+ },
+
+ computeKeysets: function(left, right) {
+ /* Returns an array of three arrays (overlap, left_only,
+ * right_only), representing the properties common to left and
+ * right, only defined for left, and only defined for right,
+ * respectively. */
+ var overlap = [], left_only = [], right_only = [];
+ var target = overlap;
+
+ this.loopOver(left, function(obj, key) {
+ if (right[key] !== undefined) {
+ target = overlap;
+ }
+ else {
+ target = left_only;
+ }
+ target.push(key);
+ });
+ this.loopOver(right, function(obj, key) {
+ if (left[key] === undefined) {
+ right_only.push(key);
+ }
+ });
+ return [overlap, left_only, right_only];