remove lines returns the removed lines
This commit is contained in:
parent
eece670fb0
commit
2db0785544
2 changed files with 23 additions and 0 deletions
|
|
@ -123,6 +123,14 @@ var Document = function(text) {
|
||||||
this.getLines = function(firstRow, lastRow) {
|
this.getLines = function(firstRow, lastRow) {
|
||||||
return this.$lines.slice(firstRow, lastRow+1);
|
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() {
|
this.getLength = function() {
|
||||||
return this.$lines.length;
|
return this.$lines.length;
|
||||||
|
|
@ -287,6 +295,13 @@ var Document = function(text) {
|
||||||
return range.start;
|
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) {
|
this.removeLines = function(firstRow, lastRow) {
|
||||||
var range = new Range(firstRow, 0, lastRow, this.$lines[lastRow].length);
|
var range = new Range(firstRow, 0, lastRow, this.$lines[lastRow].length);
|
||||||
var removed = this.$lines.splice(firstRow, lastRow - firstRow + 1);
|
var removed = this.$lines.splice(firstRow, lastRow - firstRow + 1);
|
||||||
|
|
@ -298,6 +313,7 @@ var Document = function(text) {
|
||||||
lines: removed
|
lines: removed
|
||||||
};
|
};
|
||||||
this._dispatchEvent("change", { data: delta });
|
this._dispatchEvent("change", { data: delta });
|
||||||
|
return removed;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.removeNewLine = function(row) {
|
this.removeNewLine = function(row) {
|
||||||
|
|
|
||||||
|
|
@ -231,6 +231,13 @@ var Test = {
|
||||||
doc.remove(new Range(1, 0, 3, 0));
|
doc.remove(new Range(1, 0, 3, 0));
|
||||||
assert.equal(doc.getValue(), ["1234", ""].join("\n"));
|
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() {
|
"test: should handle unix style new lines" : function() {
|
||||||
var doc = new Document(["1", "2", "3"]);
|
var doc = new Document(["1", "2", "3"]);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue