Merge pull request #1073 from ajaxorg/c9

small changes needed for c9
This commit is contained in:
Lennart Kats 2012-11-05 01:28:24 -08:00
commit 109e9326a9
4 changed files with 130 additions and 45 deletions

View file

@ -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);

View file

@ -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;
};
});

View file

@ -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);

View file

@ -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<topLevelNamespaces.length; i++) {
var ns = topLevelNamespaces[i];
var path = this.$normalizePath(require.toUrl(ns, null, "_").replace(/.js(\?.*)?$/, ""));
tlns[ns] = path;
}
topLevelNamespaces.forEach(function(ns) {
tlns[ns] = normalizePath(require.toUrl(ns, null, "_").replace(/.js(\?.*)?$/, ""));
});
}
this.$worker = new Worker(workerUrl);
this.$worker.postMessage({
init : true,
tlns: tlns,
@ -75,12 +73,20 @@ var WorkerClient = function(topLevelNamespaces, mod, classname) {
this.callbackId = 1;
this.callbacks = {};
var _self = this;
this.$worker.onerror = function(e) {
this.$worker.onerror = this.onError;
this.$worker.onmessage = this.onMessage;
};
(function(){
oop.implement(this, EventEmitter);
this.onError = function(e) {
window.console && console.log && console.log(e);
throw e;
};
this.$worker.onmessage = function(e) {
this.onMessage = function(e) {
var msg = e.data;
switch(msg.type) {
case "log":
@ -88,23 +94,18 @@ var WorkerClient = function(topLevelNamespaces, mod, classname) {
break;
case "event":
_self._emit(msg.name, {data: msg.data});
this._emit(msg.name, {data: msg.data});
break;
case "call":
var callback = _self.callbacks[msg.id];
var callback = this.callbacks[msg.id];
if (callback) {
callback(msg.data);
delete _self.callbacks[msg.id];
delete this.callbacks[msg.id];
}
break;
}
};
};
(function(){
oop.implement(this, EventEmitter);
this.$normalizePath = function(path) {
if (!location.host) // needed for file:// protocol
@ -166,6 +167,51 @@ var WorkerClient = function(topLevelNamespaces, mod, classname) {
}).call(WorkerClient.prototype);
var UIWorkerClient = function(topLevelNamespaces, mod, classname) {
this.changeListener = this.changeListener.bind(this);
this.callbackId = 1;
this.callbacks = {};
this.messageBuffer = [];
var main = null;
var sender = Object.create(EventEmitter);
var _self = this;
this.$worker = {}
this.$worker.postMessage = function(e) {
_self.messageBuffer.push(e);
main && setTimeout(processNext);
};
var processNext = function() {
var msg = _self.messageBuffer.shift();
if (msg.command)
main[msg.command].apply(main, msg.args);
else if (msg.event)
sender._emit(msg.event, msg.data);
};
sender.postMessage = function(msg) {
_self.onMessage({data: msg});
};
sender.callback = function(data, callbackId) {
this.postMessage({type: "call", id: callbackId, data: data});
};
sender.emit = function(name, data) {
this.postMessage({type: "event", name: name, data: data});
};
require([mod], function(Main) {
main = new Main[classname](sender);
while (_self.messageBuffer.length)
processNext();
});
};
UIWorkerClient.prototype = WorkerClient.prototype;
exports.UIWorkerClient = UIWorkerClient;
exports.WorkerClient = WorkerClient;
});