You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
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);
|
|
|
|
};
|
|
|
|
return module.exports;
|
|
|
|
});
|