Ensure there is always at least one line if a empty document is created

This commit is contained in:
Julian Viereck 2011-02-06 19:18:14 +08:00 • committed by Fabian Jakobs
commit 3b29651731
2 changed files with 19 additions and 9 deletions

View file

@ -46,6 +46,11 @@ var Document = function(text) {
if (Array.isArray(text)) { if (Array.isArray(text)) {
this.insertLines(0, text); this.insertLines(0, 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.
else if (text.length == 0) {
this.$lines = [""];
} else { } else {
this.insert({row: 0, column:0}, text); this.insert({row: 0, column:0}, text);
} }

View file

@ -292,6 +292,11 @@ var Test = {
doc.setValue(doc.getValue()); doc.setValue(doc.getValue());
assert.equal("1\n2", doc.getValue()); assert.equal("1\n2", doc.getValue());
},
"test: empty document has to contain one line": function() {
var doc = new Document("");
assert.equal(doc.$lines.length, 1);
} }
}; };