refactor undo handling
This commit is contained in:
parent
6dfe5cb1ba
commit
14b7b5ad4b
4 changed files with 37 additions and 65 deletions
|
|
@ -183,14 +183,12 @@ var Document = function(text) {
|
|||
var firstLine = lines.splice(0, 1)[0];
|
||||
var lastLine = lines.length == 0 ? null : lines.splice(lines.length - 1, 1)[0];
|
||||
|
||||
this._dispatchEvent("changeStart");
|
||||
position = this.insertInLine(position, firstLine);
|
||||
if (lastLine !== null) {
|
||||
position = this.insertNewLine(position); // terminate first line
|
||||
position = this.insertLines(position.row, lines);
|
||||
position = this.insertInLine(position, lastLine || "");
|
||||
}
|
||||
this._dispatchEvent("changeEnd");
|
||||
return position;
|
||||
};
|
||||
|
||||
|
|
@ -202,7 +200,6 @@ var Document = function(text) {
|
|||
args.push.apply(args, lines);
|
||||
this.$lines.splice.apply(this.$lines, args);
|
||||
|
||||
this._dispatchEvent("changeStart");
|
||||
var range = new Range(row, 0, row + lines.length, 0);
|
||||
var delta = {
|
||||
action: "insertLines",
|
||||
|
|
@ -210,7 +207,6 @@ var Document = function(text) {
|
|||
lines: lines
|
||||
};
|
||||
this._dispatchEvent("change", { data: delta });
|
||||
this._dispatchEvent("changeEnd");
|
||||
return range.end;
|
||||
},
|
||||
|
||||
|
|
@ -218,7 +214,6 @@ var Document = function(text) {
|
|||
position = this.$clipPosition(position);
|
||||
var line = this.$lines[position.row] || "";
|
||||
|
||||
this._dispatchEvent("changeStart");
|
||||
this.$lines[position.row] = line.substring(0, position.column);
|
||||
this.$lines.splice(position.row + 1, 0, line.substring(position.column, line.length));
|
||||
|
||||
|
|
@ -233,7 +228,6 @@ var Document = function(text) {
|
|||
text: this.getNewLineCharacter()
|
||||
};
|
||||
this._dispatchEvent("change", { data: delta });
|
||||
this._dispatchEvent("changeEnd");
|
||||
|
||||
return end;
|
||||
};
|
||||
|
|
@ -244,7 +238,6 @@ var Document = function(text) {
|
|||
|
||||
var line = this.$lines[position.row] || "";
|
||||
|
||||
this._dispatchEvent("changeStart");
|
||||
this.$lines[position.row] = line.substring(0, position.column) + text
|
||||
+ line.substring(position.column);
|
||||
|
||||
|
|
@ -259,7 +252,6 @@ var Document = function(text) {
|
|||
text: text
|
||||
};
|
||||
this._dispatchEvent("change", { data: delta });
|
||||
this._dispatchEvent("changeEnd");
|
||||
|
||||
return end;
|
||||
};
|
||||
|
|
@ -275,7 +267,6 @@ var Document = function(text) {
|
|||
var firstRow = range.start.row;
|
||||
var lastRow = range.end.row;
|
||||
|
||||
this._dispatchEvent("changeStart");
|
||||
if (range.isMultiLine()) {
|
||||
var firstFullRow = range.start.column == 0 ? firstRow : firstRow + 1;
|
||||
var lastFullRow = lastRow - 1;
|
||||
|
|
@ -294,7 +285,6 @@ var Document = function(text) {
|
|||
else {
|
||||
this.removeInLine(firstRow, range.start.column, range.end.column);
|
||||
}
|
||||
this._dispatchEvent("changeEnd");
|
||||
return range.start;
|
||||
};
|
||||
|
||||
|
|
@ -306,7 +296,6 @@ var Document = function(text) {
|
|||
var line = this.getLine(row);
|
||||
var removed = line.substring(startColumn, endColumn);
|
||||
var newLine = line.substring(0, startColumn) + line.substring(endColumn, line.length);
|
||||
this._dispatchEvent("changeStart");
|
||||
this.$lines.splice(row, 1, newLine);
|
||||
|
||||
var delta = {
|
||||
|
|
@ -315,7 +304,6 @@ var Document = function(text) {
|
|||
text: removed
|
||||
};
|
||||
this._dispatchEvent("change", { data: delta });
|
||||
this._dispatchEvent("changeEnd");
|
||||
return range.start;
|
||||
};
|
||||
|
||||
|
|
@ -327,7 +315,6 @@ var Document = function(text) {
|
|||
* @return {String[]} The removed lines
|
||||
*/
|
||||
this.removeLines = function(firstRow, lastRow) {
|
||||
this._dispatchEvent("changeStart");
|
||||
var range = new Range(firstRow, 0, lastRow + 1, 0);
|
||||
var removed = this.$lines.splice(firstRow, lastRow - firstRow + 1);
|
||||
|
||||
|
|
@ -338,7 +325,6 @@ var Document = function(text) {
|
|||
lines: removed
|
||||
};
|
||||
this._dispatchEvent("change", { data: delta });
|
||||
this._dispatchEvent("changeEnd");
|
||||
return removed;
|
||||
};
|
||||
|
||||
|
|
@ -349,7 +335,6 @@ var Document = function(text) {
|
|||
var range = new Range(row, firstLine.length, row+1, 0);
|
||||
var line = firstLine + secondLine;
|
||||
|
||||
this._dispatchEvent("changeStart");
|
||||
this.$lines.splice(row, 2, line);
|
||||
|
||||
var delta = {
|
||||
|
|
@ -358,7 +343,6 @@ var Document = function(text) {
|
|||
text: this.getNewLineCharacter()
|
||||
};
|
||||
this._dispatchEvent("change", { data: delta });
|
||||
this._dispatchEvent("changeEnd");
|
||||
};
|
||||
|
||||
this.replace = function(range, text) {
|
||||
|
|
@ -370,7 +354,6 @@ var Document = function(text) {
|
|||
if (text == this.getTextRange(range))
|
||||
return range.end;
|
||||
|
||||
this._dispatchEvent("changeStart");
|
||||
this.remove(range);
|
||||
if (text) {
|
||||
var end = this.insert(range.start, text);
|
||||
|
|
@ -378,7 +361,6 @@ var Document = function(text) {
|
|||
else {
|
||||
end = range.start;
|
||||
}
|
||||
this._dispatchEvent("changeEnd");
|
||||
|
||||
return end;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue