Refactored out TextPatcher and JsonOT and replaced with new ChainPad

This commit is contained in:
Caleb James DeLisle
2017-11-09 15:36:49 +01:00
parent 7f8147b18b
commit 75130150d5
31 changed files with 82 additions and 1447 deletions

25
www/common/text-cursor.js Normal file
View File

@@ -0,0 +1,25 @@
define([
], function () {
var module = { exports: {} };
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;
};
module.exports.transformCursor = function (cursor, ops) {
if (Array.isArray(ops)) {
for (var i = ops.length - 1; i >= 0; i--) { transformCursor(cursor, ops[i]); }
return;
}
transformCursor(ops);
};
});