New cursor recovery system (beta)

This commit is contained in:
yflory
2018-11-26 16:23:16 +01:00
parent 518c1e0d3e
commit dbad925e5e
2 changed files with 240 additions and 6 deletions

View File

@@ -306,6 +306,7 @@ define([
return true;
}
/*
cursor.update();
// no use trying to recover the cursor if it doesn't exist
@@ -314,6 +315,7 @@ define([
/* 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; }
@@ -325,19 +327,15 @@ define([
if (frame & 1) {
// push cursor start if necessary
cursor.transformRange(cursor.Range.start, ops);
/*if (pushes.commonStart < cursor.Range.start.offset) {
cursor.Range.start.offset += pushes.delta;
}*/
}
if (frame & 2) {
// push cursor end if necessary
cursor.transformRange(cursor.Range.end, ops);
/*if (pushes.commonStart < cursor.Range.end.offset) {
cursor.Range.end.offset += pushes.delta;
}*/
}
}
*/
},
/*
postDiffApply: function (info) {
if (info.frame) {
if (info.node) {
@@ -351,6 +349,7 @@ define([
cursor.fixSelection(sel, range);
}
}
*/
};
};
@@ -515,9 +514,19 @@ define([
$(el).remove();
});
// Get cursor position
cursor.offsetUpdate();
var oldText = inner.outerHTML;
// Apply the changes
var patch = (DD).diff(inner, userDocStateDom);
(DD).apply(inner, patch);
// Restore cursor position
var newText = inner.outerHTML;
var ops = ChainPad.Diff.diff(oldText, newText);
cursor.restoreOffset(ops);
// MEDIATAG: Migrate old mediatags to the widget system
$(inner).find('media-tag:not(.cke_widget_element)').each(function (i, el) {
var element = new window.CKEDITOR.dom.element(el);