Ensure there is always at least one line if a empty document is created
This commit is contained in:
parent
17578e42cb
commit
3b29651731
2 changed files with 19 additions and 9 deletions
|
|
@ -46,6 +46,11 @@ var Document = function(text) {
|
|||
|
||||
if (Array.isArray(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 {
|
||||
this.insert({row: 0, column:0}, text);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -292,6 +292,11 @@ var Test = {
|
|||
|
||||
doc.setValue(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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue