From e04b37c0627ad8bf1bb3f73f7ab48c338b819bd8 Mon Sep 17 00:00:00 2001 From: nightwing Date: Sun, 7 Apr 2013 22:19:04 +0400 Subject: [PATCH 1/3] add cursorStyle option --- lib/ace/editor.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 0abcecbf..14174422 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -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}, From 477d381185591346a2c059c30537ae46f5f700b1 Mon Sep 17 00:00:00 2001 From: nightwing Date: Tue, 9 Apr 2013 16:44:17 +0400 Subject: [PATCH 2/3] do not send deltas to worker synchronously since it is slow and crashes chrome --- lib/ace/worker/mirror.js | 2 +- lib/ace/worker/worker_client.js | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/ace/worker/mirror.js b/lib/ace/worker/mirror.js index 198432be..c521f8fd 100644 --- a/lib/ace/worker/mirror.js +++ b/lib/ace/worker/mirror.js @@ -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); }); }; diff --git a/lib/ace/worker/worker_client.js b/lib/ace/worker/worker_client.js index b9cf7851..d54c38a7 100644 --- a/lib/ace/worker/worker_client.js +++ b/lib/ace/worker/worker_client.js @@ -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; }); From 886da0d0dc05b9fa4b68cab475dddac7c2c4bc97 Mon Sep 17 00:00:00 2001 From: nightwing Date: Tue, 9 Apr 2013 22:14:30 +0400 Subject: [PATCH 3/3] fix setDefaultValue for useWorker --- lib/ace/edit_session.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index a2faea1a..5ae66232 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -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); };