Adding empty lines on "reload"
This commit is contained in:
Fabian Jakobs 2011-02-02 09:47:21 +01:00
commit d2e0f8305f
4 changed files with 121 additions and 95 deletions

View file

@ -57,8 +57,8 @@ var Document = function(text) {
this.setValue = function(text) {
var len = this.getLength();
this.remove(new Range(0, 0, len, this.getLine(len-1).length));
this.insertLines(0, this.$split(text));
this.remove(new Range(0, 0, len, this.getLine(len-1).length));
this.insert({row: 0, column:0}, text);
};
this.getValue = function() {
@ -262,14 +262,20 @@ var Document = function(text) {
var firstRow = range.start.row;
var lastRow = range.end.row;
if (range.isMultiLine()) {
// TODO removeInLine can be optimized away!
this.removeInLine(lastRow, 0, range.end.column);
if (lastRow - firstRow >= 2)
this.removeLines(firstRow + 1, lastRow - 1);
this.removeInLine(firstRow, range.start.column, this.$lines[firstRow].length);
this.removeNewLine(range.start.row);
if (range.isMultiLine()) {
var firstFullRow = range.start.column == 0 ? firstRow : firstRow + 1;
var lastFullRow = lastRow - 1;
if (range.end.column > 0)
this.removeInLine(lastRow, 0, range.end.column);
if (lastFullRow >= firstFullRow)
this.removeLines(firstFullRow, lastFullRow);
if (firstFullRow != firstRow) {
this.removeInLine(firstRow, range.start.column, this.$lines[firstRow].length);
this.removeNewLine(range.start.row);
}
}
else {
this.removeInLine(firstRow, range.start.column, range.end.column);