Generalize for document

This commit is contained in:
Garen Torikian 2012-05-10 15:53:29 -07:00 • committed by nightwing
commit 84e3687e01
2 changed files with 11 additions and 13 deletions

View file

@ -42,7 +42,7 @@ var oop = require("./lib/oop");
var EventEmitter = require("./lib/event_emitter").EventEmitter; var EventEmitter = require("./lib/event_emitter").EventEmitter;
var Range = require("./range").Range; var Range = require("./range").Range;
var Anchor = require("./anchor").Anchor; var Anchor = require("./anchor").Anchor;
var lang = require("./lib/lang");
/** /**
* class Document * class Document
* *
@ -327,14 +327,7 @@ var Document = function(text) {
return {row: row, column: 0}; return {row: row, column: 0};
var args = [row, 0]; var args = [row, 0];
var step = 100000; this.$lines = lang.chunkLines(lines, this.$lines, args, true);
var l = Math.ceil(lines.length / step);
for (var tlines, i = 0; i < l; i++) {
tlines = lines.slice(i * step, step);
args.push.apply(args, tlines);
this.$lines.splice.apply(this.$lines, args);
}
var range = new Range(row, 0, row + lines.length, 0); var range = new Range(row, 0, row + lines.length, 0);
var delta = { var delta = {
action: "insertLines", action: "insertLines",

View file

@ -147,8 +147,8 @@ exports.deferredCall = function(fcn) {
return deferred; return deferred;
}; };
// because of Document, this is confusing as shit
exports.chunkLines = function(args, thingToSplice, thingtoApply) { exports.chunkLines = function(args, thingToSplice, thingtoApply, isDocument) {
if (thingtoApply === undefined) if (thingtoApply === undefined)
thingtoApply = thingToSplice; thingtoApply = thingToSplice;
@ -156,7 +156,12 @@ exports.chunkLines = function(args, thingToSplice, thingtoApply) {
var l = Math.ceil(args.length / step); var l = Math.ceil(args.length / step);
for (var targs, i = 0; i < l; i++) { for (var targs, i = 0; i < l; i++) {
targs = args.slice(i * step, step); targs = args.slice(i * step, step);
thingToSplice.slice.apply(thingtoApply, targs); if (isDocument) {
thingtoApply.push.apply(thingtoApply, targs);
thingToSplice.splice.apply(thingToSplice, thingtoApply);
}
else
thingToSplice.slice.apply(thingtoApply, targs);
} }
return thingToSplice; return thingToSplice;