diff --git a/lib/ace/document.js b/lib/ace/document.js index 0e6258a4..db6e4d54 100644 --- a/lib/ace/document.js +++ b/lib/ace/document.js @@ -123,6 +123,14 @@ var Document = function(text) { this.getLines = function(firstRow, lastRow) { return this.$lines.slice(firstRow, lastRow+1); }; + + /** + * Returns all lines in the document as string array. Warning: The caller + * should not modify this array! + */ + this.getAllLines = function() { + return this.$lines; + }; this.getLength = function() { return this.$lines.length; @@ -287,6 +295,13 @@ var Document = function(text) { return range.start; }; + /** + * Removes a range of full lines + * + * @param firstRow {Integer} The first row to be removed + * @param firstRow {Integer} The first row to be removed + * @return {String[]} The removed lines + */ this.removeLines = function(firstRow, lastRow) { var range = new Range(firstRow, 0, lastRow, this.$lines[lastRow].length); var removed = this.$lines.splice(firstRow, lastRow - firstRow + 1); @@ -298,6 +313,7 @@ var Document = function(text) { lines: removed }; this._dispatchEvent("change", { data: delta }); + return removed; }; this.removeNewLine = function(row) { diff --git a/lib/ace/test/document_test.js b/lib/ace/test/document_test.js index 5fc27ec3..2d8f9b33 100644 --- a/lib/ace/test/document_test.js +++ b/lib/ace/test/document_test.js @@ -231,6 +231,13 @@ var Test = { doc.remove(new Range(1, 0, 3, 0)); assert.equal(doc.getValue(), ["1234", ""].join("\n")); }, + + "test: remove lines should return the removed lines" : function() { + var doc = new Document(["1234", "5678", "abcd"]); + + var removed = doc.removeLines(1, 2); + assert.equal(removed.join("\n"), ["5678", "abcd"].join("\n")); + }, "test: should handle unix style new lines" : function() { var doc = new Document(["1", "2", "3"]);