diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index b23a60ec..8ff4be29 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -148,17 +148,14 @@ var SearchHighlight = require("./search_highlight").SearchHighlight; **/ var EditSession = function(text, mode) { - this.$modified = true; this.$breakpoints = []; this.$decorations = []; this.$frontMarkers = {}; this.$backMarkers = {}; this.$markerId = 1; - this.$resetRowCache(0); - this.$wrapData = []; - this.$foldData = []; - this.$rowLengthCache = []; this.$undoSelect = true; + + this.$foldData = []; this.$foldData.toString = function() { var str = ""; this.forEach(function(foldLine) { @@ -166,12 +163,13 @@ var EditSession = function(text, mode) { }); return str; } + this.on("changeFold", this.onChangeFold.bind(this)); + this.$onChange = this.onChange.bind(this); + + if (typeof text != "object" || !text.getLine) + text = new Document(text); - if (typeof text == "object" && text.getLine) { - this.setDocument(text); - } else { - this.setDocument(new Document(text)); - } + this.setDocument(text); this.selection = new Selection(this); this.setMode(mode); @@ -191,16 +189,15 @@ var EditSession = function(text, mode) { **/ this.setDocument = function(doc) { if (this.doc) - throw new Error("Document is already set"); + this.doc.removeListener("change", this.$onChange); this.doc = doc; - doc.on("change", this.onChange.bind(this)); - this.on("changeFold", this.onChangeFold.bind(this)); + doc.on("change", this.$onChange); - if (this.bgTokenizer) { + if (this.bgTokenizer) this.bgTokenizer.setDocument(this.getDocument()); - this.bgTokenizer.start(0); - } + + this.resetCaches(); }; /** @@ -253,6 +250,15 @@ var EditSession = function(text, mode) { return low && low -1; }; + this.resetCaches = function() { + this.$modified = true; + this.$wrapData = []; + this.$rowLengthCache = []; + this.$resetRowCache(0); + if (this.bgTokenizer) + this.bgTokenizer.start(0); + }; + this.onChangeFold = function(e) { var fold = e.data; this.$resetRowCache(fold.start.row); diff --git a/lib/ace/lib/lang.js b/lib/ace/lib/lang.js index e9585dca..6ea59761 100644 --- a/lib/ace/lib/lang.js +++ b/lib/ace/lib/lang.js @@ -134,7 +134,7 @@ exports.getMatchOffsets = function(string, regExp) { return matches; }; - +/* deprecated */ exports.deferredCall = function(fcn) { var timer = null; @@ -166,4 +166,39 @@ exports.deferredCall = function(fcn) { return deferred; }; + +exports.delayedCall = function(fcn, defaultTimeout) { + var timer = null; + var callback = function() { + timer = null; + fcn(); + }; + + var _self = function(timeout) { + timer && clearTimeout(timer); + timer = setTimeout(callback, timeout || defaultTimeout); + }; + + _self.delay = delayed; + _self.schedule = function(timeout) { + if (timer == null) + timer = setTimeout(callback, timeout || 0); + }; + + _self.call = function() { + this.cancel(); + fcn(); + }; + + _self.cancel = function() { + timer && clearTimeout(timer); + timer = null; + }; + + _self.isPending = function() { + return timer; + }; + + return _self; +}; }); diff --git a/lib/ace/mode/xquery_worker.js b/lib/ace/mode/xquery_worker.js index cf01e423..863a06e3 100644 --- a/lib/ace/mode/xquery_worker.js +++ b/lib/ace/mode/xquery_worker.js @@ -36,8 +36,6 @@ var Mirror = require("../worker/mirror").Mirror; var JSONParseTreeHandler = require("./xquery/JSONParseTreeHandler").JSONParseTreeHandler; var XQueryParser = require("./xquery/XQueryParser").XQueryParser; var SyntaxHighlighter = require("../mode/xquery/visitors/SyntaxHighlighter").SyntaxHighlighter; -window.addEventListener = function() {}; - var XQueryWorker = exports.XQueryWorker = function(sender) { Mirror.call(this, sender); diff --git a/lib/ace/worker/worker_client.js b/lib/ace/worker/worker_client.js index d3b9c3c8..8f11ff4b 100644 --- a/lib/ace/worker/worker_client.js +++ b/lib/ace/worker/worker_client.js @@ -3,7 +3,7 @@ * * Copyright (c) 2010, Ajax.org B.V. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ * * Neither the name of Ajax.org B.V. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -36,14 +36,15 @@ var EventEmitter = require("../lib/event_emitter").EventEmitter; var config = require("../config"); var WorkerClient = function(topLevelNamespaces, mod, classname) { - this.changeListener = this.changeListener.bind(this); + this.onMessage = this.onMessage.bind(this); + this.onError = this.onError.bind(this); + var workerUrl; if (config.get("packaged")) { - this.$worker = new Worker(config.moduleUrl(mod, "worker")); - } - else { - var workerUrl; + workerUrl = config.moduleUrl(mod, "worker"); + } else { + var normalizePath = this.$normalizePath; if (typeof require.supports !== "undefined" && require.supports.indexOf("ucjs2-pinf-0") >= 0) { // We are running in the sourcemint loader. workerUrl = require.nameToUrl("ace/worker/worker_sourcemint"); @@ -52,19 +53,16 @@ var WorkerClient = function(topLevelNamespaces, mod, classname) { // nameToUrl is renamed to toUrl in requirejs 2 if (require.nameToUrl && !require.toUrl) require.toUrl = require.nameToUrl; - workerUrl = this.$normalizePath(require.toUrl("ace/worker/worker", null, "_")); + workerUrl = normalizePath(require.toUrl("ace/worker/worker", null, "_")); } - this.$worker = new Worker(workerUrl); var tlns = {}; - for (var i=0; i