Merge pull request #2523 from ajaxorg/fix/various

Fix several small issues
This commit is contained in:
Lennart Kats 2015-06-01 17:59:08 +02:00
commit f10da4cdb0
10 changed files with 133 additions and 26 deletions

View file

@ -39,7 +39,7 @@ function warn() {
s.shift(); // remove the getter
s = s.join("\n");
// allow easy access to ace in console, but not in ace code
if (!/at Object.InjectedScript.|@debugger eval|snippets:\/{3}/.test(s)) {
if (!/at Object.InjectedScript.|@debugger eval|snippets:\/{3}|\(<anonymous>:\d+:\d+\)/.test(s)) {
console.error("trying to access to global variable");
}
}

View file

@ -2,15 +2,13 @@
* Simple node.js server, which generates the synax highlighted version of itself
* using the Ace modes and themes on the server and serving a static web page.
*/
// $'
// include ace search path and modules
require("amd-loader");
// load jsdom, which is required by Ace
require("../../lib/ace/test/mockdom");
var http = require("http");
var fs = require("fs");
var resolve = require("path").resolve;
// load the highlighter and the desired mode and theme
var highlighter = require("../../lib/ace/ext/static_highlight");
@ -20,15 +18,22 @@ var theme = require("../../lib/ace/theme/twilight");
var port = process.env.PORT || 2222;
http.createServer(function(req, res) {
var url = req.url;
var path = /[^#?\x00]*/.exec(url)[0];
var root = resolve(__dirname + "/../../").replace(/\\/g, "/");
path = resolve(root + "/" + path).replace(/\\/g, "/");
if (path.indexOf(root + "/") != 0)
path = __filename;
res.writeHead(200, {"Content-Type": "text/html; charset=utf-8"});
fs.readFile(__dirname + "/../../build/src/ace.js", "utf8", function(err, data) {
fs.readFile(path, "utf8", function(err, data) {
if (err) data = err.message;
var highlighted = highlighter.render(data, new JavaScriptMode(), theme);
res.end(
'<html><body>\n' +
'<style type="text/css" media="screen">\n' +
highlighted.css +
'</style>\n' +
highlighted.html +
highlighted.html +
'</body></html>'
);
});

View file

@ -100,7 +100,7 @@ var Autocomplete = function() {
var rect = editor.container.getBoundingClientRect();
pos.top += rect.top - renderer.layerConfig.offset;
pos.left += rect.left - editor.renderer.scrollLeft;
pos.left += renderer.$gutterLayer.gutterWidth;
pos.left += renderer.gutterWidth;
this.popup.show(pos, lineHeight);
} else if (keepPopupPosition && !prefix) {

View file

@ -37,6 +37,10 @@ var baseStyles = require("../requirejs/text!./static.css");
var config = require("../config");
var dom = require("../lib/dom");
var SimpleTextLayer = function() {
this.config = {};
};
SimpleTextLayer.prototype = TextLayer.prototype;
var highlight = function(el, opts, callback) {
var m = el.className.match(/lang-(\w+)/);
@ -149,12 +153,8 @@ highlight.renderSync = function(input, mode, theme, lineStart, disableGutter) {
session.setUseWorker(false);
session.setMode(mode);
var textLayer = new TextLayer(document.createElement("div"));
var textLayer = new SimpleTextLayer();
textLayer.setSession(session);
textLayer.config = {
characterWidth: 10,
lineHeight: 20
};
session.setValue(input);

View file

@ -91,6 +91,11 @@ exports.toggleCssClass = function(el, name) {
return add;
};
if (typeof document == "undefined") {
exports.importCssString = function() {};
return;
}
/*
* Add or remove a CSS class from the list of classes on the given node
* depending on the value of <tt>include</tt>
@ -173,9 +178,6 @@ exports.getInnerHeight = function(element) {
};
if (typeof document == "undefined")
return;
if (window.pageYOffset !== undefined) {
exports.getPageScrollTop = function() {
return window.pageYOffset;

View file

@ -83,7 +83,7 @@ function onMouseDown(e) {
var selectionMode;
if (editor.$mouseHandler.$enableJumpToDef) {
if (ctrl && alt || accel && alt)
selectionMode = "add";
selectionMode = shift ? "block" : "add";
else if (alt && editor.$blockSelectEnabled)
selectionMode = "block";
} else {
@ -117,7 +117,7 @@ function onMouseDown(e) {
if (shift) {
oldRange = null;
range = selection.ranges[0];
range = selection.ranges[0] || range;
editor.removeSelectionMarker(range);
}
editor.once("mouseup", function() {

View file

@ -21,7 +21,7 @@ http.createServer(function(req, res) {
if (req.method == "PUT") {
if (!allowSave)
return error(res, 404, "Saving not allowed pass --allow-save to enable");
save(req, res, filename);
return save(req, res, filename);
}
fs.exists(filename, function(exists) {
@ -86,6 +86,7 @@ function save(req, res, filePath) {
}
res.statusCode = 200;
res.end("OK");
console.log("saved ", filePath);
});
}

View file

@ -14,8 +14,16 @@ exports.parsePlist = function(xmlOrJSON, callback) {
});
} else {
try {
xmlOrJSON = xmlOrJSON.replace(/^\s*\/\/.*/gm, "");
json = JSON.parse(xmlOrJSON)
xmlOrJSON = xmlOrJSON.replace(
/("(?:\\.|[^"])*")|(?:,\s*)+([\]\}])|(\w+)\s*:|([\]\}]\s*[\[\{])|(\/\/.*|\/\*(?:[^\*]|\*(?=[^\/]))*?\*\/)/g,
function(_, str, extraComma, noQuote, missingComma, comment) {
if (comment)
return "";
if (missingComma)
return missingComma[0] + "," + missingComma.slice(1);
return str || extraComma || '"' + noQuote + '":';
});
json = JSON.parse(xmlOrJSON);
} catch(e) {
json = cson.parse(xmlOrJSON);
}
@ -24,10 +32,101 @@ exports.parsePlist = function(xmlOrJSON, callback) {
return json;
};
exports.formatJSON = function(object, initialIndent) {
return util.inspect(object, false, 40).replace(/^/gm, initialIndent||"");
return JSON.stringify(object, null, 4).replace(/^/gm, initialIndent||"");
};
exports.formatJS = function(object, initialIndent) {
return formatJS(object, 4, initialIndent);
};
function formatJS(object, indent, initialIndent) {
if (typeof indent == "number")
indent = Array(indent + 1).join(" ");
function $format(buffer, totalIndent, state, o) {
if (typeof o != "object" || !o) {
if (typeof o == "string")
buffer.push(JSON.stringify(o));
else
buffer.push("" + o);
}
else if (Array.isArray(o)) {
buffer.push("[")
var len = totalIndent.length
var oneLine = true;
for (var i = 0; i < o.length; i++) {
if (typeof o[i] == "string") {
len += o[i].length + 2
} else if (!o[i]) {
len += (o[i] + "").length
} else {
oneLine = false;
break;
}
len += 2;
if (len > 60) {
oneLine = false;
break;
}
}
for (var i = 0; i < o.length; i++) {
if (o[i] && typeof o[i] == "object") {
$format(buffer, totalIndent, state, o[i]);
if (i < o.length - 1)
buffer.push(", ");
} else {
if (oneLine)
i && buffer.push(" ");
else
buffer.push("\n", totalIndent + indent)
$format(buffer, totalIndent + indent, state, o[i]);
if (i < o.length - 1)
buffer.push(",");
}
}
if (!oneLine && buffer[buffer.length - 1] != "}")
buffer.push("\n" + totalIndent)
buffer.push("]")
}
else {
var keys = Object.keys(o);
buffer.push("{", "\n");
for (var i = 0; i < keys.length; i++) {
buffer.push(totalIndent + indent);
if (/^\w+$/.test(keys[i]))
buffer.push(keys[i]);
else
buffer.push(JSON.stringify(keys[i]));
buffer.push(": ")
if (keys[i] == "regex" && typeof o[keys[i]] == "string") {
try {
var re = new RegExp(o[keys[i]]);
buffer.push("/" + re.source.replace(/\\.|\//g, function(f) {
return f.length == 1 ? "\\" + f : f;
}) + "/");
} catch(e) {
$format(buffer, totalIndent + indent, state, o[keys[i]]);
}
} else {
$format(buffer, totalIndent + indent, state, o[keys[i]]);
}
if (i < keys.length - 1)
buffer.push(",", "\n");
}
buffer.push("\n", totalIndent, "}");
}
}
var buffer = [];
$format(buffer, initialIndent || "", {}, object);
return buffer.join("");
}
exports.fillTemplate = function(template, replacements) {
return template.replace(/%(.+?)%/g, function(str, m) {

View file

@ -126,8 +126,8 @@ function handleSaveResult(err, editor) {
return log(
"Write access to this file is disabled.\n"+
"To enable saving your changes to disk, clone the Ace repository\n"+
"and run the included web server with the --allow-write option\n"+
"`node static.js --allow-write` or `static.py --puttable=*`"
"and run the included web server with the --allow-save option\n"+
"`node static.js --allow-save` or `static.py --puttable=*`"
);
}
editor.session.getUndoManager().markClean();

View file

@ -662,10 +662,10 @@ function convertTmLanguage(name, langStr) {
var languageHighlightRules = lib.fillTemplate(modeHighlightTemplate, {
language: languageNameSanitized,
languageTokens: lib.formatJSON(patterns, " ").trim(),
languageTokens: lib.formatJS(patterns, " ").trim(),
uuid: language.uuid,
name: name,
metaData: lib.formatJSON(language, " ").trim()
metaData: lib.formatJS(language, "").trim()
});
if (devMode) {