Fix error with setValue("\nfoo") when wrap mode is on

This commit is contained in:
Joe Cheng 2011-02-17 14:33:20 +08:00 committed by Fabian Jakobs
commit 95d3a2ada7
2 changed files with 21 additions and 0 deletions

View file

@ -183,10 +183,17 @@ var Document = function(text) {
var end = this.insertInLine(position, text);
}
else {
// Insert the first line
if (newLines[0].length > 0) {
var end = this.insertInLine(position, newLines[0]);
this.insertNewLine(end);
}
else {
this.insertNewLine(position);
}
// Now insert remaining lines
// If we are inserting at the end of the document, we don't need to
// use insertInLine (concorde depends on this optimization!)
if (position.row + 1 == this.getLength()) {

View file

@ -325,6 +325,20 @@ var Test = {
assert.equal(session.$wrapData.length, 2);
assert.equal(session.$wrapData[0].length, 1);
assert.equal(session.$wrapData[1].length, 1);
},
"test first line blank with wrap": function() {
var session = new EditSession("\nfoo");
session.setUseWrapMode(true);
assert.equal(session.doc.getValue(), ["", "foo"].join("\n"));
},
"test first line blank with wrap 2" : function() {
var session = new EditSession("");
session.setUseWrapMode(true);
session.setValue("\nfoo");
assert.equal(session.doc.getValue(), ["", "foo"].join("\n"));
}
};