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);
this.setDocument(text);
this.selection = new Selection(this);
this.setMode(mode);
config.resetOptions(this);
this.setMode(mode);
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);
@ -2209,13 +2218,14 @@ config.defineOptions(Editor.prototype, "editor", {
initialValue: true
},
readOnly: {
set: function(readOnly) {
this.textInput.setReadOnly(readOnly);
var cursorLayer = this.renderer.$cursorLayer;
cursorLayer && cursorLayer.setBlinking(!readOnly);
},
set: function(readOnly) { this.$resetCursorStyle(); },
initialValue: false
},
cursorStyle: {
set: function(val) { this.$resetCursorStyle(); },
values: ["ace", "slim", "smooth", "wide"],
initialValue: "ace"
},
behavioursEnabled: {initialValue: true},
wrapBehavioursEnabled: {initialValue: true},

View file

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

View file

@ -36,6 +36,7 @@ var EventEmitter = require("../lib/event_emitter").EventEmitter;
var config = require("../config");
var WorkerClient = function(topLevelNamespaces, mod, classname) {
this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this);
this.changeListener = this.changeListener.bind(this);
this.onMessage = this.onMessage.bind(this);
this.onError = this.onError.bind(this);
@ -152,17 +153,28 @@ var WorkerClient = function(topLevelNamespaces, mod, classname) {
};
this.changeListener = function(e) {
e.range = {
start: e.data.range.start,
end: e.data.range.end
};
this.emit("change", e);
if (!this.deltaQueue) {
this.deltaQueue = [e.data];
setTimeout(this.$sendDeltaQueue, 1);
} else
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);
var UIWorkerClient = function(topLevelNamespaces, mod, classname) {
this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this);
this.changeListener = this.changeListener.bind(this);
this.callbackId = 1;
this.callbacks = {};
@ -207,6 +219,6 @@ var UIWorkerClient = function(topLevelNamespaces, mod, classname) {
UIWorkerClient.prototype = WorkerClient.prototype;
exports.UIWorkerClient = UIWorkerClient;
exports.WorkerClient = WorkerClient;
exports.WorkerClient = UIWorkerClient;
});