From 79c0f83e2c988f17c76ffc7605c0f19945f1db34 Mon Sep 17 00:00:00 2001 From: nightwing Date: Mon, 26 Aug 2013 21:52:38 +0400 Subject: [PATCH] add input event, make doing multiple changes in one turn much faster --- lib/ace/background_tokenizer.js | 6 ++++-- lib/ace/editor.js | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/ace/background_tokenizer.js b/lib/ace/background_tokenizer.js index 2fe9dceb..1eb28794 100644 --- a/lib/ace/background_tokenizer.js +++ b/lib/ace/background_tokenizer.js @@ -170,6 +170,10 @@ var BackgroundTokenizer = function(tokenizer, editor) { // pretty long delay to prevent the tokenizer from interfering with the user this.running = setTimeout(this.$worker, 700); }; + + this.scheduleStart = function() { + this.running = setTimeout(this.$worker, 700); + } this.$updateOnChange = function(delta) { var range = delta.range; @@ -191,8 +195,6 @@ var BackgroundTokenizer = function(tokenizer, editor) { this.currentLine = Math.min(startRow, this.currentLine, this.doc.getLength()); this.stop(); - // pretty long delay to prevent the tokenizer from interfering with the user - this.running = setTimeout(this.$worker, 700); }; /** diff --git a/lib/ace/editor.js b/lib/ace/editor.js index afd98874..e22875d5 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -90,6 +90,15 @@ var Editor = function(renderer, session) { this.commands.on("exec", this.$historyTracker); this.$initOperationListeners(); + + this._$emitInputEvent = lang.delayedCall(function() { + this._signal("input", {}); + this.session.bgTokenizer && this.session.bgTokenizer.scheduleStart(); + }.bind(this)); + + this.on("change", function(_, _self) { + _self._$emitInputEvent.schedule(31); + }); this.setSession(session || new EditSession("")); config.resetOptions(this);