Add changeDelta event on the document

This commit is contained in:
Julian Viereck 2011-01-10 17:18:14 +01:00
commit ddd5b3093d

View file

@ -511,15 +511,17 @@ var Document = function(text, mode) {
args.push.apply(args, lines);
this.lines.splice.apply(this.lines, args);
var delta = {
action: "insertText",
range: new Range(row, 0, row + lines.length, 0),
text: lines.join(nl) + nl
};
if (!fromUndo && this.$undoManager) {
var nl = this.$getNewLineCharacter();
this.$deltas.push({
action: "insertText",
range: new Range(row, 0, row + lines.length, 0),
text: lines.join(nl) + nl
});
this.$deltas.push(delta);
this.$informUndoManager.schedule();
}
this._dispatchEvent("changeDelta", { data: delta });
},
this.$insert = function(position, text, fromUndo) {
@ -571,14 +573,16 @@ var Document = function(text, mode) {
};
}
var delta = {
action: "insertText",
range: Range.fromPoints(position, end),
text: text
};
if (!fromUndo && this.$undoManager) {
this.$deltas.push({
action: "insertText",
range: Range.fromPoints(position, end),
text: text
});
this.$deltas.push(delta);
this.$informUndoManager.schedule();
}
this._dispatchEvent("changeDelta", { data: delta });
return end;
};
@ -623,13 +627,13 @@ var Document = function(text, mode) {
if (range.isEmpty())
return;
var delta = {
action: "removeText",
range: range.clone(),
text: this.getTextRange(range)
};
if (!fromUndo && this.$undoManager) {
var nl = this.$getNewLineCharacter();
this.$deltas.push({
action: "removeText",
range: range.clone(),
text: this.getTextRange(range)
});
this.$deltas.push(delta);
this.$informUndoManager.schedule();
}
@ -645,6 +649,8 @@ var Document = function(text, mode) {
this.lines.splice(firstRow, lastRow - firstRow + 1, row);
else
this.lines.splice(firstRow, lastRow - firstRow + 1, "");
this._dispatchEvent("changeDelta", { data: delta });
return range.start;
};