fix inserting long text

This commit is contained in:
nightwing 2014-02-15 12:12:26 +04:00
commit 316bb55f17

View file

@ -56,7 +56,7 @@ var Document = function(text) {
// There has to be one line at least in the document. If you pass an empty
// string to the insert function, nothing will happen. Workaround.
if (text.length == 0) {
if (text.length === 0) {
this.$lines = [""];
} else if (Array.isArray(text)) {
this._insertLines(0, text);
@ -107,10 +107,10 @@ var Document = function(text) {
**/
// check for IE split bug
if ("aaa".split(/a/).length == 0)
if ("aaa".split(/a/).length === 0)
this.$split = function(text) {
return text.replace(/\r\n|\r/g, "\n").split("\n");
}
};
else
this.$split = function(text) {
return text.split(/\r\n|\r|\n/);
@ -136,11 +136,11 @@ var Document = function(text) {
case "unix":
return "\n";
default:
return this.$autoNewLine;
return this.$autoNewLine || "\n";
}
};
this.$autoNewLine = "\n";
this.$autoNewLine = "";
this.$newLineMode = "auto";
/**
* [Sets the new line mode.]{: #Document.setNewLineMode.desc}
@ -311,9 +311,10 @@ var Document = function(text) {
// 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
if (lines.length > 0xFFFF) {
var end = this._insertLines(row, lines.slice(0xFFFF));
lines = lines.slice(0, 0xFFFF);
while (lines.length > 0xF000) {
var end = this._insertLines(row, lines.slice(0, 0xF000));
lines = lines.slice(0xF000);
row = end.row;
}
var args = [row, 0];
@ -327,7 +328,7 @@ var Document = function(text) {
lines: lines
};
this._signal("change", { data: delta });
return end || range.end;
return range.end;
};
/**