Add changeDelta event on the document
This commit is contained in:
parent
a71f50ac9a
commit
ddd5b3093d
1 changed files with 22 additions and 16 deletions
|
|
@ -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);
|
||||||
|
|
||||||
|
var delta = {
|
||||||
|
action: "insertText",
|
||||||
|
range: new Range(row, 0, row + lines.length, 0),
|
||||||
|
text: lines.join(nl) + nl
|
||||||
|
};
|
||||||
if (!fromUndo && this.$undoManager) {
|
if (!fromUndo && this.$undoManager) {
|
||||||
var nl = this.$getNewLineCharacter();
|
var nl = this.$getNewLineCharacter();
|
||||||
this.$deltas.push({
|
this.$deltas.push(delta);
|
||||||
action: "insertText",
|
|
||||||
range: new Range(row, 0, row + lines.length, 0),
|
|
||||||
text: lines.join(nl) + nl
|
|
||||||
});
|
|
||||||
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) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var delta = {
|
||||||
|
action: "insertText",
|
||||||
|
range: Range.fromPoints(position, end),
|
||||||
|
text: text
|
||||||
|
};
|
||||||
if (!fromUndo && this.$undoManager) {
|
if (!fromUndo && this.$undoManager) {
|
||||||
this.$deltas.push({
|
this.$deltas.push(delta);
|
||||||
action: "insertText",
|
|
||||||
range: Range.fromPoints(position, end),
|
|
||||||
text: text
|
|
||||||
});
|
|
||||||
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;
|
||||||
|
|
||||||
|
var delta = {
|
||||||
|
action: "removeText",
|
||||||
|
range: range.clone(),
|
||||||
|
text: this.getTextRange(range)
|
||||||
|
};
|
||||||
if (!fromUndo && this.$undoManager) {
|
if (!fromUndo && this.$undoManager) {
|
||||||
var nl = this.$getNewLineCharacter();
|
this.$deltas.push(delta);
|
||||||
this.$deltas.push({
|
|
||||||
action: "removeText",
|
|
||||||
range: range.clone(),
|
|
||||||
text: this.getTextRange(range)
|
|
||||||
});
|
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue