add start/endOperation
This commit is contained in:
parent
b18b86b6c9
commit
ec8b42c5e0
1 changed files with 60 additions and 2 deletions
|
|
@ -88,7 +88,9 @@ var Editor = function(renderer, session) {
|
||||||
|
|
||||||
this.$historyTracker = this.$historyTracker.bind(this);
|
this.$historyTracker = this.$historyTracker.bind(this);
|
||||||
this.commands.on("exec", this.$historyTracker);
|
this.commands.on("exec", this.$historyTracker);
|
||||||
|
|
||||||
|
this.$initOperationListeners();
|
||||||
|
|
||||||
this.setSession(session || new EditSession(""));
|
this.setSession(session || new EditSession(""));
|
||||||
config.resetOptions(this);
|
config.resetOptions(this);
|
||||||
config._emit("editor", this);
|
config._emit("editor", this);
|
||||||
|
|
@ -97,7 +99,63 @@ var Editor = function(renderer, session) {
|
||||||
(function(){
|
(function(){
|
||||||
|
|
||||||
oop.implement(this, EventEmitter);
|
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) {
|
this.$historyTracker = function(e) {
|
||||||
if (!this.$mergeUndoDeltas)
|
if (!this.$mergeUndoDeltas)
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue