add start/endOperation

This commit is contained in:
nightwing 2013-06-17 16:30:09 +04:00
commit ec8b42c5e0

View file

@ -88,7 +88,9 @@ var Editor = function(renderer, session) {
this.$historyTracker = this.$historyTracker.bind(this);
this.commands.on("exec", this.$historyTracker);
this.$initOperationListeners();
this.setSession(session || new EditSession(""));
config.resetOptions(this);
config._emit("editor", this);
@ -97,7 +99,63 @@ var Editor = function(renderer, session) {
(function(){
oop.implement(this, EventEmitter);
this.$initOperationListeners = function() {
function last(a) {return a[a.length - 1]};
this.selections = [];
this.commands.on("exec", function(e) {
this.startOperation(e);
}.bind(this), true);
this.commands.on("afterExec", function(e) {
this.endOperation(e);
}.bind(this), true);
this.$opResetTimer = lang.delayedCall(this.endOperation.bind(this));
this.on("change", function() {
this.curOp || this.startOperation();
this.curOp.docChanged = true;
}.bind(this), true);
this.on("changeSelection", function() {
this.curOp || this.startOperation();
this.curOp.selectionChanged = true;
}.bind(this), true);
}
this.curOp = null;
this.prevOp = {};
this.startOperation = function(commadEvent) {
if (this.curOp) {
if (!commadEvent || this.curOp.command)
return;
this.prevOp = this.curOp;
}
if (!commadEvent) {
this.previousCommand = null;
commadEvent = {};
}
this.$opResetTimer.schedule();
this.curOp = {
command: commadEvent.command || {},
args: commadEvent.args
};
this.selections.push(this.selection.toJSON());
};
this.endOperation = function() {
if (this.curOp) {
this.prevOp = this.curOp;
this.curOp = null;
}
};
this.$historyTracker = function(e) {
if (!this.$mergeUndoDeltas)
return;