From 84e3687e0133cbe0918aba86c02bea327ad9dd59 Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Thu, 10 May 2012 15:53:29 -0700 Subject: [PATCH] Generalize for document --- lib/ace/document.js | 11 ++--------- lib/ace/lib/lang.js | 13 +++++++++---- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/ace/document.js b/lib/ace/document.js index 1c89fcf1..8f1a9f08 100644 --- a/lib/ace/document.js +++ b/lib/ace/document.js @@ -42,7 +42,7 @@ var oop = require("./lib/oop"); var EventEmitter = require("./lib/event_emitter").EventEmitter; var Range = require("./range").Range; var Anchor = require("./anchor").Anchor; - +var lang = require("./lib/lang"); /** * class Document * @@ -327,14 +327,7 @@ var Document = function(text) { return {row: row, column: 0}; var args = [row, 0]; - var step = 100000; - 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); - } - + this.$lines = lang.chunkLines(lines, this.$lines, args, true); var range = new Range(row, 0, row + lines.length, 0); var delta = { action: "insertLines", diff --git a/lib/ace/lib/lang.js b/lib/ace/lib/lang.js index bc118b2c..8477b65c 100644 --- a/lib/ace/lib/lang.js +++ b/lib/ace/lib/lang.js @@ -147,16 +147,21 @@ exports.deferredCall = function(fcn) { return deferred; }; - -exports.chunkLines = function(args, thingToSplice, thingtoApply) { +// because of Document, this is confusing as shit +exports.chunkLines = function(args, thingToSplice, thingtoApply, isDocument) { if (thingtoApply === undefined) thingtoApply = thingToSplice; - + var step = 100000; var l = Math.ceil(args.length / step); for (var targs, i = 0; i < l; i++) { 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;