Merge branch 'cjd-fixed-it-with-hax' into netflux2
This commit is contained in:
@@ -372,7 +372,7 @@ var random = Patch.random = function (doc, opCount) {
|
||||
var PARANOIA = module.exports.PARANOIA = false;
|
||||
|
||||
/* throw errors over non-compliant messages which would otherwise be treated as invalid */
|
||||
var TESTING = module.exports.TESTING = false;
|
||||
var TESTING = module.exports.TESTING = true;
|
||||
|
||||
var assert = module.exports.assert = function (expr) {
|
||||
if (!expr) { throw new Error("Failed assertion"); }
|
||||
@@ -1443,7 +1443,13 @@ var rebase = Operation.rebase = function (oldOp, newOp) {
|
||||
* @param transformBy an existing operation which also has the same base.
|
||||
* @return toTransform *or* null if the result is a no-op.
|
||||
*/
|
||||
var transform0 = Operation.transform0 = function (text, toTransform, transformBy) {
|
||||
|
||||
var transform0 = Operation.transform0 = function (text, toTransformOrig, transformByOrig) {
|
||||
// Cloning the original transformations makes this algorithm such that it
|
||||
// **DOES NOT MUTATE ANYMORE**
|
||||
var toTransform = Operation.clone(toTransformOrig);
|
||||
var transformBy = Operation.clone(transformByOrig);
|
||||
|
||||
if (toTransform.offset > transformBy.offset) {
|
||||
if (toTransform.offset > transformBy.offset + transformBy.toRemove) {
|
||||
// simple rebase
|
||||
|
||||
@@ -373,6 +373,26 @@ define([
|
||||
};
|
||||
};
|
||||
|
||||
cursor.brFix = function () {
|
||||
cursor.update();
|
||||
var start = Range.start;
|
||||
var end = Range.end;
|
||||
if (!start.el) { return; }
|
||||
|
||||
if (start.el === end.el && start.offset === end.offset) {
|
||||
if (start.el.tagName === 'BR') {
|
||||
// get the parent element, which ought to be a P.
|
||||
var P = start.el.parentNode;
|
||||
|
||||
[cursor.fixStart, cursor.fixEnd].forEach(function (f) {
|
||||
f(P, 0);
|
||||
});
|
||||
|
||||
cursor.fixSelection(cursor.makeSelection(), cursor.makeRange());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return cursor;
|
||||
};
|
||||
});
|
||||
|
||||
@@ -54,7 +54,7 @@ define([], function () {
|
||||
The function, if provided, must return true for elements which
|
||||
should be preserved, and 'false' for elements which should be removed.
|
||||
*/
|
||||
var DOM2HyperJSON = function(el, predicate){
|
||||
var DOM2HyperJSON = function(el, predicate, filter){
|
||||
if(!el.tagName && el.nodeType === Node.TEXT_NODE){
|
||||
return el.textContent;
|
||||
}
|
||||
@@ -118,12 +118,16 @@ define([], function () {
|
||||
i = 0;
|
||||
|
||||
for(; i < el.childNodes.length; i++){
|
||||
children.push(DOM2HyperJSON(el.childNodes[i], predicate));
|
||||
children.push(DOM2HyperJSON(el.childNodes[i], predicate, filter));
|
||||
}
|
||||
|
||||
result.push(children.filter(isTruthy));
|
||||
|
||||
return result;
|
||||
if (filter) {
|
||||
return filter(result);
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
@@ -5,19 +5,45 @@ define([
|
||||
var JsonOT = {};
|
||||
|
||||
var validate = JsonOT.validate = function (text, toTransform, transformBy) {
|
||||
var resultOp = ChainPad.Operation.transform0(text, toTransform, transformBy);
|
||||
var text2 = ChainPad.Operation.apply(transformBy, text);
|
||||
var text3 = ChainPad.Operation.apply(resultOp, text2);
|
||||
try {
|
||||
JSON.parse(text3);
|
||||
return resultOp;
|
||||
} catch (e) {
|
||||
var resultOp = ChainPad.Operation.transform0(text, toTransform, transformBy);
|
||||
var text2 = ChainPad.Operation.apply(transformBy, text);
|
||||
var text3 = ChainPad.Operation.apply(resultOp, text2);
|
||||
try {
|
||||
JSON.parse(text3);
|
||||
return resultOp;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
var info = window.REALTIME_MODULE.ot_parseError = {
|
||||
type: 'resultParseError',
|
||||
resultOp: resultOp,
|
||||
|
||||
toTransform: toTransform,
|
||||
transformBy: transformBy,
|
||||
|
||||
text1: text,
|
||||
text2: text2,
|
||||
text3: text3,
|
||||
error: e
|
||||
};
|
||||
console.log('Debugging info available at `window.REALTIME_MODULE.ot_parseError`');
|
||||
}
|
||||
} catch (x) {
|
||||
console.error(x);
|
||||
console.error(e);
|
||||
console.log({
|
||||
var info = window.REALTIME_MODULE.ot_applyError = {
|
||||
type: 'resultParseError',
|
||||
resultOp: resultOp,
|
||||
|
||||
toTransform: toTransform,
|
||||
transformBy: transformBy,
|
||||
|
||||
text1: text,
|
||||
text2: text2,
|
||||
text3: text3
|
||||
});
|
||||
text3: text3,
|
||||
error: e
|
||||
};
|
||||
console.log('Debugging info available at `window.REALTIME_MODULE.ot_applyError`');
|
||||
}
|
||||
|
||||
// returning **null** breaks out of the loop
|
||||
|
||||
Reference in New Issue
Block a user