diff --git a/www/_socket/main.js b/www/_socket/main.js
index 67bfaff89..042bd3c20 100644
--- a/www/_socket/main.js
+++ b/www/_socket/main.js
@@ -45,6 +45,16 @@ define([
return true;
};
+ /* catch `type="_moz"` before it goes over the wire */
+ var brFilter = function (hj) {
+ if (hj[1].type === '_moz') { hj[1].type = undefined; }
+ return hj;
+ };
+
+ var stringifyDOM = function (dom) {
+ return JSON.stringify(Hyperjson.fromDOM(dom, isNotMagicLine, brFilter));
+ };
+
var andThen = function (Ckeditor) {
$(window).on('hashchange', function() {
window.location.reload();
@@ -76,6 +86,8 @@ define([
var inner = window.inner = documentBody;
var cursor = window.cursor = Cursor(inner);
+
+
var setEditable = function (bool) {
// careful about putting attributes onto the DOM
// they get put into the chain, and you can have trouble
@@ -165,8 +177,7 @@ define([
doc: inner,
// provide initialstate...
- initialState: JSON.stringify(Hyperjson
- .fromDOM(inner, isNotMagicLine)) || '{}',
+ initialState: stringifyDOM(inner) || '{}',
// really basic operational transform
// reject patch if it results in invalid JSON
@@ -221,7 +232,8 @@ define([
// build a dom from HJSON, diff, and patch the editor
applyHjson(shjson);
- var shjson2 = JSON.stringify(Hyperjson.fromDOM(inner));
+ var shjson2 = stringifyDOM(inner);
+
if (shjson2 !== shjson) {
console.error("shjson2 !== shjson");
module.realtimeInput.patchText(shjson2);
@@ -255,11 +267,6 @@ define([
var rti = module.realtimeInput = realtimeInput.start(realtimeOptions);
- /* catch `type="_moz"` before it goes over the wire */
- var brFilter = function (hj) {
- if (hj[1].type === '_moz') { hj[1].type = undefined; }
- return hj;
- };
/* It's incredibly important that you assign 'rti.onLocal'
It's used inside of realtimeInput to make sure that all changes
@@ -270,7 +277,7 @@ define([
the code less extensible.
*/
var propogate = rti.onLocal = function () {
- var shjson = JSON.stringify(Hyperjson.fromDOM(inner, isNotMagicLine, brFilter));
+ var shjson = stringifyDOM(inner);
if (!rti.patchText(shjson)) {
return;
}
diff --git a/www/common/RealtimeTextSocket.js b/www/common/RealtimeTextSocket.js
index edb8e3791..4821ce454 100644
--- a/www/common/RealtimeTextSocket.js
+++ b/www/common/RealtimeTextSocket.js
@@ -264,7 +264,8 @@ define([
}, 200);
toReturn.patchText = TextPatcher.create({
- realtime: realtime
+ realtime: realtime,
+ logging: true
});
realtime.start();
diff --git a/www/common/TextPatcher.js b/www/common/TextPatcher.js
index 66858826d..98ccea65a 100644
--- a/www/common/TextPatcher.js
+++ b/www/common/TextPatcher.js
@@ -23,8 +23,8 @@ var diff = function (oldval, newval) {
commonEnd++;
}
- var toRemove;
- var toInsert;
+ var toRemove = 0;
+ var toInsert = '';
/* throw some assertions in here before dropping patches into the realtime */
if (oldval.length !== commonStart + commonEnd) {
@@ -79,14 +79,15 @@ var log = function (text, op) {
Due to its reliance on patch, applyChange has side effects on the supplied
realtime facade.
*/
-var applyChange = function(ctx, oldval, newval) {
+var applyChange = function(ctx, oldval, newval, logging) {
var op = diff(oldval, newval);
- // log(oldval, op)
+ if (logging) { log(oldval, op) }
patch(ctx, op);
};
var create = function(config) {
var ctx = config.realtime;
+ var logging = config.logging;
// initial state will always fail the !== check in genop.
// because nothing will equal this object
@@ -100,7 +101,7 @@ var create = function(config) {
// propogate()
return function (newContent) {
if (newContent !== content) {
- applyChange(ctx, ctx.getUserDoc(), newContent);
+ applyChange(ctx, ctx.getUserDoc(), newContent, logging);
if (ctx.getUserDoc() !== newContent) {
console.log("Expected that: `ctx.getUserDoc() === newContent`!");
}
diff --git a/www/common/chainpad.js b/www/common/chainpad.js
index 9d9dcc071..134d80ce2 100644
--- a/www/common/chainpad.js
+++ b/www/common/chainpad.js
@@ -368,7 +368,7 @@ var random = Patch.random = function (doc, opCount) {
* along with this program. If not, see