Merge branch 'cursor' into staging
This commit is contained in:
commit
3d712d9008
@ -124,6 +124,7 @@ define([
|
|||||||
|
|
||||||
cursor.pushDelta = function (oldVal, newVal) {
|
cursor.pushDelta = function (oldVal, newVal) {
|
||||||
if (oldVal === newVal) { return; }
|
if (oldVal === newVal) { return; }
|
||||||
|
|
||||||
var commonStart = 0;
|
var commonStart = 0;
|
||||||
while (oldVal.charAt(commonStart) === newVal.charAt(commonStart)) {
|
while (oldVal.charAt(commonStart) === newVal.charAt(commonStart)) {
|
||||||
commonStart++;
|
commonStart++;
|
||||||
@ -156,6 +157,31 @@ define([
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
cursor.transformRange = function (cursorRange, ops) {
|
||||||
|
var transformCursor = function (cursor, op) {
|
||||||
|
if (!op) { return cursor; }
|
||||||
|
|
||||||
|
var pos = op.offset;
|
||||||
|
var remove = op.toRemove;
|
||||||
|
var insert = op.toInsert.length;
|
||||||
|
if (typeof cursor === 'undefined') { return; }
|
||||||
|
if (typeof remove === 'number' && pos < cursor) {
|
||||||
|
cursor -= Math.min(remove, cursor - pos);
|
||||||
|
}
|
||||||
|
if (typeof insert === 'number' && pos < cursor) {
|
||||||
|
cursor += insert;
|
||||||
|
}
|
||||||
|
return cursor;
|
||||||
|
};
|
||||||
|
var c = cursorRange.offset;
|
||||||
|
if (Array.isArray(ops)) {
|
||||||
|
for (var i = ops.length - 1; i >= 0; i--) {
|
||||||
|
c = transformCursor(c, ops[i]);
|
||||||
|
}
|
||||||
|
cursorRange.offset = c;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
cursor.brFix = function () {
|
cursor.brFix = function () {
|
||||||
cursor.update();
|
cursor.update();
|
||||||
var start = Range.start;
|
var start = Range.start;
|
||||||
|
|||||||
@ -259,6 +259,9 @@ define([
|
|||||||
if (content === UNINITIALIZED) { return; }
|
if (content === UNINITIALIZED) { return; }
|
||||||
throw new Error("Content must be an object or array, type is " + typeof(content));
|
throw new Error("Content must be an object or array, type is " + typeof(content));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
oldContent = content;
|
||||||
|
|
||||||
if (Array.isArray(content)) {
|
if (Array.isArray(content)) {
|
||||||
// Pad
|
// Pad
|
||||||
content.push({ metadata: cpNfInner.metadataMgr.getMetadataLazy() });
|
content.push({ metadata: cpNfInner.metadataMgr.getMetadataLazy() });
|
||||||
|
|||||||
@ -318,20 +318,23 @@ define([
|
|||||||
|
|
||||||
if (!frame) { return; }
|
if (!frame) { return; }
|
||||||
|
|
||||||
if (typeof info.diff.oldValue === 'string' && typeof info.diff.newValue === 'string') {
|
if (frame && typeof info.diff.oldValue === 'string' && typeof info.diff.newValue === 'string') {
|
||||||
var pushes = cursor.pushDelta(info.diff.oldValue, info.diff.newValue);
|
//var pushes = cursor.pushDelta(info.diff.oldValue, info.diff.newValue);
|
||||||
|
var ops = ChainPad.Diff.diff(info.diff.oldValue, info.diff.newValue);
|
||||||
|
|
||||||
if (frame & 1) {
|
if (frame & 1) {
|
||||||
// push cursor start if necessary
|
// push cursor start if necessary
|
||||||
if (pushes.commonStart < cursor.Range.start.offset) {
|
cursor.transformRange(cursor.Range.start, ops);
|
||||||
|
/*if (pushes.commonStart < cursor.Range.start.offset) {
|
||||||
cursor.Range.start.offset += pushes.delta;
|
cursor.Range.start.offset += pushes.delta;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
if (frame & 2) {
|
if (frame & 2) {
|
||||||
// push cursor end if necessary
|
// push cursor end if necessary
|
||||||
if (pushes.commonStart < cursor.Range.end.offset) {
|
cursor.transformRange(cursor.Range.end, ops);
|
||||||
|
/*if (pushes.commonStart < cursor.Range.end.offset) {
|
||||||
cursor.Range.end.offset += pushes.delta;
|
cursor.Range.end.offset += pushes.delta;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user