diff --git a/lib/ace/document.js b/lib/ace/document.js index 490ee225..b0e7d2d8 100644 --- a/lib/ace/document.js +++ b/lib/ace/document.js @@ -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()) { diff --git a/lib/ace/test/edit_session_test.js b/lib/ace/test/edit_session_test.js index f5b72140..3cb061bb 100644 --- a/lib/ace/test/edit_session_test.js +++ b/lib/ace/test/edit_session_test.js @@ -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")); } };