simple-text-buffer
Version:
A version of Atom's text-buffer with marker layers and file support removed
41 lines (36 loc) • 1.43 kB
JavaScript
(function() {
var Point, SpliceArrayChunkSize,
slice = [].slice;
Point = require('./point');
SpliceArrayChunkSize = 100000;
module.exports = {
spliceArray: function(originalArray, start, length, insertedArray) {
var chunk, chunkEnd, chunkStart, i, ref, ref1, removedValues;
if (insertedArray == null) {
insertedArray = [];
}
if (insertedArray.length < SpliceArrayChunkSize) {
return originalArray.splice.apply(originalArray, [start, length].concat(slice.call(insertedArray)));
} else {
removedValues = originalArray.splice(start, length);
for (chunkStart = i = 0, ref = insertedArray.length, ref1 = SpliceArrayChunkSize; ref1 > 0 ? i <= ref : i >= ref; chunkStart = i += ref1) {
chunkEnd = chunkStart + SpliceArrayChunkSize;
chunk = insertedArray.slice(chunkStart, chunkEnd);
originalArray.splice.apply(originalArray, [start + chunkStart, 0].concat(slice.call(chunk)));
}
return removedValues;
}
},
newlineRegex: /\r\n|\n|\r/g,
normalizePatchChanges: function(changes) {
return changes.map(function(change) {
return {
start: Point.fromObject(change.newStart),
oldExtent: Point.fromObject(change.oldExtent),
newExtent: Point.fromObject(change.newExtent),
newText: change.newText
};
});
}
};
}).call(this);