Add changeDelta event on the document

Conflicts:

	lib/ace/document.js
This commit is contained in:
Fabian Jakobs 2011-01-14 16:23:31 +01:00
commit 7ccd377f13

View file

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