From ec8b42c5e060b191070f9b7b03eb1ca541849401 Mon Sep 17 00:00:00 2001 From: nightwing Date: Mon, 17 Jun 2013 16:30:09 +0400 Subject: [PATCH] add start/endOperation --- lib/ace/editor.js | 62 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 97e78d36..6771c0dd 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -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;