diff --git a/lib/ace/document.js b/lib/ace/document.js index 10a36eb2..2e6e5db3 100644 --- a/lib/ace/document.js +++ b/lib/ace/document.js @@ -311,11 +311,12 @@ var Document = function(text) { if (lines.length == 0) return {row: row, column: 0}; - // apply doesn't work for big arrays (smallest threshold is on safari 0xFFFF) - // to circumvent that we have to break huge inserts into smaller chunks here - while (lines.length > 0xF000) { - var end = this._insertLines(row, lines.slice(0, 0xF000)); - lines = lines.slice(0xF000); + // Apply doesn't work for big arrays due to max call stack detection. + // Chrome 64 bit requires threshold smaller than 32k, using a safe value of 20k. + // To circumvent that we have to break huge inserts into smaller chunks here. + while (lines.length > 20000) { + var end = this._insertLines(row, lines.slice(0, 20000)); + lines = lines.slice(20000); row = end.row; } diff --git a/lib/ace/document_test.js b/lib/ace/document_test.js index 5c324db0..051434b4 100644 --- a/lib/ace/document_test.js +++ b/lib/ace/document_test.js @@ -296,6 +296,35 @@ module.exports = { "test: empty document has to contain one line": function() { var doc = new Document(""); assert.equal(doc.$lines.length, 1); + }, + + "test: ignore empty delta": function() { + var doc = new Document(""); + doc.on("change", function() { + throw "should ignore empty delta"; + }) + doc.insert({row: 0, column: 0}, ""); + doc.insert({row: 1, column: 1}, ""); + doc.remove({start: {row: 1, column: 1}, end: {row: 1, column: 1}}); + }, + + "test: inserting huge delta": function() { + var doc = new Document(""); + var val = ""; + var MAX = 0xF000; + for (var i = 0; i < 10 * MAX; i++) { + val += i + "\n" + } + doc.setValue(val); + assert.equal(doc.getValue(), val); + + for (var i = 3 * MAX + 2; i >= 3 * MAX - 2; i--) { + val = doc.getLines(0, i).join("\n"); + doc.setValue("\nab"); + assert.equal(doc.getValue(), "\nab"); + doc.insert({row: 1, column: 1}, val); + assert.equal(doc.getValue(), "\na" + val + "b"); + } } };