Merge branch 'vdom' of github.com:xwiki-labs/cryptpad into demoEffect
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 = true;
|
||||
var TESTING = module.exports.TESTING = false;
|
||||
|
||||
var assert = module.exports.assert = function (expr) {
|
||||
if (!expr) { throw new Error("Failed assertion"); }
|
||||
@@ -1163,6 +1163,7 @@ module.exports.create = function (userName, authToken, channelId, initialState,
|
||||
Common.assert(typeof(initialState) === 'string');
|
||||
var realtime = ChainPad.create(userName, authToken, channelId, initialState, conf);
|
||||
return {
|
||||
Operation: Operation,
|
||||
onPatch: enterChainPad(realtime, function (handler) {
|
||||
Common.assert(typeof(handler) === 'function');
|
||||
realtime.patchHandlers.push(handler);
|
||||
@@ -1282,7 +1283,7 @@ var clone = Operation.clone = function (op) {
|
||||
|
||||
/**
|
||||
* @param op the operation to apply.
|
||||
* @param doc the content to apply the operation on
|
||||
* @param doc the content to apply the operation on
|
||||
*/
|
||||
var apply = Operation.apply = function (op, doc)
|
||||
{
|
||||
|
||||
@@ -6,12 +6,9 @@ define([
|
||||
'/common/convert.js',
|
||||
'/common/toolbar.js',
|
||||
'/common/cursor.js',
|
||||
'/common/Operation.js',
|
||||
'/bower_components/jquery/dist/jquery.min.js',
|
||||
'/customize/pad.js'
|
||||
], function (Config, Messages, Crypto, realtimeInput, Convert, Toolbar, Cursor, Operation) {
|
||||
window.Operation = Operation;
|
||||
|
||||
], function (Config, Messages, Crypto, realtimeInput, Convert, Toolbar, Cursor) {
|
||||
var $ = window.jQuery;
|
||||
var ifrw = $('#pad-iframe')[0].contentWindow;
|
||||
window.Ckeditor = ifrw.CKEDITOR;
|
||||
@@ -107,53 +104,34 @@ define([
|
||||
onInit: onInit,
|
||||
|
||||
transformFunction : function (text, toTransform, transformBy) {
|
||||
/* FIXME
|
||||
operational transform on json shouldn't be in all editors
|
||||
just those transmitting/expecting JSON
|
||||
*/
|
||||
false && console.log({
|
||||
text: text,
|
||||
toTransform: toTransform,
|
||||
transformBy: 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) { console.log(e); }
|
||||
|
||||
// returning **null** breaks out of the loop
|
||||
// which transforms conflicting operations
|
||||
// in theory this should prevent us from producing bad JSON
|
||||
return null;
|
||||
},
|
||||
|
||||
// OT
|
||||
}
|
||||
/*
|
||||
transformFunction: function (text, toTransform, transformBy) {
|
||||
if (toTransform.offset > transformBy.offset) {
|
||||
if (toTransform.offset > transformBy.offset + transformBy.toRemove) {
|
||||
// simple rebase
|
||||
toTransform.offset -= transformBy.toRemove;
|
||||
toTransform.offset += transformBy.toInsert.length;
|
||||
|
||||
// TODO check that this is using the correct parameters
|
||||
// TODO get the actual library
|
||||
// TODO functionize this because it's repeated
|
||||
|
||||
var temp = Operation.apply(text, toTransform)
|
||||
try {
|
||||
JSON.parse(temp);
|
||||
} catch (err) {
|
||||
console.error(err.stack);
|
||||
return null;
|
||||
}
|
||||
return toTransform;
|
||||
}
|
||||
// goto the end, anything you deleted that they also deleted should be skipped.
|
||||
var newOffset = transformBy.offset + transformBy.toInsert.length;
|
||||
toTransform.toRemove = 0; //-= (newOffset - toTransform.offset);
|
||||
if (toTransform.toRemove < 0) { toTransform.toRemove = 0; }
|
||||
toTransform.offset = newOffset;
|
||||
if (toTransform.toInsert.length === 0 && toTransform.toRemove === 0) {
|
||||
return null;
|
||||
}
|
||||
return toTransform;
|
||||
FIXME NOT A REAL FUNCTION WONT WORK
|
||||
transformFunction: function (state0str, toTransform, transformBy) {
|
||||
var state1A = JSON.parse(Operation.apply(state0str, transformBy));
|
||||
var state1B = JSON.parse(Operation.apply(state0str, toTransform));
|
||||
var state0 = JSON.parse(state0str);
|
||||
}
|
||||
if (toTransform.offset + toTransform.toRemove < transformBy.offset) {
|
||||
return toTransform;
|
||||
}
|
||||
toTransform.toRemove = transformBy.offset - toTransform.offset;
|
||||
if (toTransform.toInsert.length === 0 && toTransform.toRemove === 0) {
|
||||
return null;
|
||||
}
|
||||
return toTransform;
|
||||
} */
|
||||
*/
|
||||
});
|
||||
|
||||
$textarea.val(JSON.stringify(Convert.dom.to.hjson(inner)));
|
||||
|
||||
Reference in New Issue
Block a user