|
|
@ -51,16 +51,27 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
var $textarea = $('#feedback');
|
|
|
|
var $textarea = $('#feedback');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var setEditable = function (bool) {
|
|
|
|
|
|
|
|
inner.setAttribute('contenteditable',
|
|
|
|
|
|
|
|
(typeof (bool) !== 'undefined'? bool : true));
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// don't let the user edit until the pad is ready
|
|
|
|
|
|
|
|
setEditable(false);
|
|
|
|
|
|
|
|
|
|
|
|
var diffOptions = {
|
|
|
|
var diffOptions = {
|
|
|
|
preDiffApply: function (info) {
|
|
|
|
preDiffApply: function (info) {
|
|
|
|
var frame;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// no use trying to recover the cursor if it doesn't exist
|
|
|
|
// no use trying to recover the cursor if it doesn't exist
|
|
|
|
if (!cursor.exists()) { return; }
|
|
|
|
if (!cursor.exists()) { return; }
|
|
|
|
|
|
|
|
|
|
|
|
info.frame = frame = cursor.inNode(info.node);
|
|
|
|
/* frame is either 0, 1, 2, or 3, depending on which
|
|
|
|
|
|
|
|
cursor frames were affected: none, first, last, or both
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
var frame = info.frame = cursor.inNode(info.node);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!frame) { return; }
|
|
|
|
|
|
|
|
|
|
|
|
if (frame) {
|
|
|
|
|
|
|
|
var debug = info.debug = {
|
|
|
|
var debug = info.debug = {
|
|
|
|
frame: frame,
|
|
|
|
frame: frame,
|
|
|
|
action: info.diff.action,
|
|
|
|
action: info.diff.action,
|
|
|
@ -68,30 +79,6 @@ define([
|
|
|
|
node: info.node
|
|
|
|
node: info.node
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (info.diff.action === 'removeTextElement') {
|
|
|
|
|
|
|
|
// crap. there will be a text element removal.
|
|
|
|
|
|
|
|
// that's bad news.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (frame === 1) {
|
|
|
|
|
|
|
|
// it's the starting element.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (frame === 2) {
|
|
|
|
|
|
|
|
// it's the ending element.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// both were removed.
|
|
|
|
|
|
|
|
// there might not be much we can do
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// the diff is going to run the following:
|
|
|
|
|
|
|
|
// info.node.parentNode.removeChild(node);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// avoid doing anything more?
|
|
|
|
|
|
|
|
// let the diff do its business.
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (info.diff.oldValue) { debug.oldValue = info.diff.oldValue; }
|
|
|
|
if (info.diff.oldValue) { debug.oldValue = info.diff.oldValue; }
|
|
|
|
if (info.diff.newValue) { debug.newValue = info.diff.newValue; }
|
|
|
|
if (info.diff.newValue) { debug.newValue = info.diff.newValue; }
|
|
|
|
if (typeof info.diff.oldValue === 'string' && typeof info.diff.newValue === 'string') {
|
|
|
|
if (typeof info.diff.oldValue === 'string' && typeof info.diff.newValue === 'string') {
|
|
|
@ -116,13 +103,6 @@ define([
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log("###################################");
|
|
|
|
console.log("###################################");
|
|
|
|
console.log(debug);
|
|
|
|
console.log(debug);
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
console.log("###################################");
|
|
|
|
|
|
|
|
console.log(info.diff.action);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
postDiffApply: function (info) {
|
|
|
|
postDiffApply: function (info) {
|
|
|
|
if (info.frame) {
|
|
|
|
if (info.frame) {
|
|
|
@ -139,6 +119,8 @@ define([
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var initializing = true;
|
|
|
|
|
|
|
|
|
|
|
|
// apply patches, and try not to lose the cursor in the process!
|
|
|
|
// apply patches, and try not to lose the cursor in the process!
|
|
|
|
var applyHjson = function (shjson) {
|
|
|
|
var applyHjson = function (shjson) {
|
|
|
|
var userDocStateDom = Convert.hjson.to.dom(JSON.parse(shjson));
|
|
|
|
var userDocStateDom = Convert.hjson.to.dom(JSON.parse(shjson));
|
|
|
@ -149,11 +131,13 @@ define([
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var onRemote = function (shjson) {
|
|
|
|
var onRemote = function (shjson) {
|
|
|
|
|
|
|
|
if (!initializing) {
|
|
|
|
// remember where the cursor is
|
|
|
|
// remember where the cursor is
|
|
|
|
cursor.update();
|
|
|
|
cursor.update();
|
|
|
|
|
|
|
|
|
|
|
|
// build a dom from HJSON, diff, and patch the editor
|
|
|
|
// build a dom from HJSON, diff, and patch the editor
|
|
|
|
applyHjson(shjson);
|
|
|
|
applyHjson(shjson);
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var onInit = function (info) { /* TODO initialize the toolbar */ };
|
|
|
|
var onInit = function (info) { /* TODO initialize the toolbar */ };
|
|
|
@ -165,6 +149,9 @@ define([
|
|
|
|
onInit: onInit,
|
|
|
|
onInit: onInit,
|
|
|
|
|
|
|
|
|
|
|
|
onReady: function (info) {
|
|
|
|
onReady: function (info) {
|
|
|
|
|
|
|
|
console.log("Unlocking editor");
|
|
|
|
|
|
|
|
initializing = false;
|
|
|
|
|
|
|
|
setEditable(true);
|
|
|
|
applyHjson($textarea.val());
|
|
|
|
applyHjson($textarea.val());
|
|
|
|
$textarea.trigger('keyup');
|
|
|
|
$textarea.trigger('keyup');
|
|
|
|
},
|
|
|
|
},
|
|
|
|