Merge pull request #1364 from ajaxorg/worker

Queue events before sending to the worker
This commit is contained in:
Mostafa Eweda 2013-04-11 04:07:12 -07:00
commit 19dd921127
4 changed files with 35 additions and 14 deletions

View file

@ -159,11 +159,10 @@ var EditSession = function(text, mode) {
text = new Document(text); text = new Document(text);
this.setDocument(text); this.setDocument(text);
this.selection = new Selection(this); this.selection = new Selection(this);
this.setMode(mode);
config.resetOptions(this); config.resetOptions(this);
this.setMode(mode);
config._emit("session", this); config._emit("session", this);
}; };

View file

@ -2188,6 +2188,15 @@ var Editor = function(renderer, session) {
}; };
}; };
this.$resetCursorStyle = function() {
var style = this.$cursorStyle || "ace";
var cursorLayer = this.renderer.$cursorLayer;
if (!cursorLayer)
return;
cursorLayer.setSmoothBlinking(style == "smooth");
cursorLayer.isBlinking = !this.$readOnly && style != "wide";
};
}).call(Editor.prototype); }).call(Editor.prototype);
@ -2209,13 +2218,14 @@ config.defineOptions(Editor.prototype, "editor", {
initialValue: true initialValue: true
}, },
readOnly: { readOnly: {
set: function(readOnly) { set: function(readOnly) { this.$resetCursorStyle(); },
this.textInput.setReadOnly(readOnly);
var cursorLayer = this.renderer.$cursorLayer;
cursorLayer && cursorLayer.setBlinking(!readOnly);
},
initialValue: false initialValue: false
}, },
cursorStyle: {
set: function(val) { this.$resetCursorStyle(); },
values: ["ace", "slim", "smooth", "wide"],
initialValue: "ace"
},
behavioursEnabled: {initialValue: true}, behavioursEnabled: {initialValue: true},
wrapBehavioursEnabled: {initialValue: true}, wrapBehavioursEnabled: {initialValue: true},

View file

@ -12,7 +12,7 @@ var Mirror = exports.Mirror = function(sender) {
var _self = this; var _self = this;
sender.on("change", function(e) { sender.on("change", function(e) {
doc.applyDeltas([e.data]); doc.applyDeltas(e.data);
deferredUpdate.schedule(_self.$timeout); deferredUpdate.schedule(_self.$timeout);
}); });
}; };

View file

@ -36,6 +36,7 @@ var EventEmitter = require("../lib/event_emitter").EventEmitter;
var config = require("../config"); var config = require("../config");
var WorkerClient = function(topLevelNamespaces, mod, classname) { var WorkerClient = function(topLevelNamespaces, mod, classname) {
this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this);
this.changeListener = this.changeListener.bind(this); this.changeListener = this.changeListener.bind(this);
this.onMessage = this.onMessage.bind(this); this.onMessage = this.onMessage.bind(this);
this.onError = this.onError.bind(this); this.onError = this.onError.bind(this);
@ -152,17 +153,28 @@ var WorkerClient = function(topLevelNamespaces, mod, classname) {
}; };
this.changeListener = function(e) { this.changeListener = function(e) {
e.range = { if (!this.deltaQueue) {
start: e.data.range.start, this.deltaQueue = [e.data];
end: e.data.range.end setTimeout(this.$sendDeltaQueue, 1);
}; } else
this.emit("change", e); this.deltaQueue.push(e.data);
}; };
this.$sendDeltaQueue = function() {
var q = this.deltaQueue;
if (!q) return;
this.deltaQueue = null;
if (q.length > 20 && q.length > this.$doc.getLength() >> 1) {
this.call("setValue", [this.$doc.getValue()]);
} else
this.emit("change", {data: q});
}
}).call(WorkerClient.prototype); }).call(WorkerClient.prototype);
var UIWorkerClient = function(topLevelNamespaces, mod, classname) { var UIWorkerClient = function(topLevelNamespaces, mod, classname) {
this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this);
this.changeListener = this.changeListener.bind(this); this.changeListener = this.changeListener.bind(this);
this.callbackId = 1; this.callbackId = 1;
this.callbacks = {}; this.callbacks = {};
@ -207,6 +219,6 @@ var UIWorkerClient = function(topLevelNamespaces, mod, classname) {
UIWorkerClient.prototype = WorkerClient.prototype; UIWorkerClient.prototype = WorkerClient.prototype;
exports.UIWorkerClient = UIWorkerClient; exports.UIWorkerClient = UIWorkerClient;
exports.WorkerClient = WorkerClient; exports.WorkerClient = UIWorkerClient;
}); });