Merge pull request #2523 from ajaxorg/fix/various
Fix several small issues
This commit is contained in:
commit
f10da4cdb0
10 changed files with 133 additions and 26 deletions
|
|
@ -39,7 +39,7 @@ function warn() {
|
||||||
s.shift(); // remove the getter
|
s.shift(); // remove the getter
|
||||||
s = s.join("\n");
|
s = s.join("\n");
|
||||||
// allow easy access to ace in console, but not in ace code
|
// 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");
|
console.error("trying to access to global variable");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,13 @@
|
||||||
* Simple node.js server, which generates the synax highlighted version of itself
|
* 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.
|
* using the Ace modes and themes on the server and serving a static web page.
|
||||||
*/
|
*/
|
||||||
// $'
|
|
||||||
// include ace search path and modules
|
// include ace search path and modules
|
||||||
require("amd-loader");
|
require("amd-loader");
|
||||||
|
|
||||||
// load jsdom, which is required by Ace
|
|
||||||
require("../../lib/ace/test/mockdom");
|
|
||||||
|
|
||||||
var http = require("http");
|
var http = require("http");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
|
var resolve = require("path").resolve;
|
||||||
|
|
||||||
// load the highlighter and the desired mode and theme
|
// load the highlighter and the desired mode and theme
|
||||||
var highlighter = require("../../lib/ace/ext/static_highlight");
|
var highlighter = require("../../lib/ace/ext/static_highlight");
|
||||||
|
|
@ -20,8 +18,15 @@ var theme = require("../../lib/ace/theme/twilight");
|
||||||
var port = process.env.PORT || 2222;
|
var port = process.env.PORT || 2222;
|
||||||
|
|
||||||
http.createServer(function(req, res) {
|
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"});
|
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);
|
var highlighted = highlighter.render(data, new JavaScriptMode(), theme);
|
||||||
res.end(
|
res.end(
|
||||||
'<html><body>\n' +
|
'<html><body>\n' +
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ var Autocomplete = function() {
|
||||||
var rect = editor.container.getBoundingClientRect();
|
var rect = editor.container.getBoundingClientRect();
|
||||||
pos.top += rect.top - renderer.layerConfig.offset;
|
pos.top += rect.top - renderer.layerConfig.offset;
|
||||||
pos.left += rect.left - editor.renderer.scrollLeft;
|
pos.left += rect.left - editor.renderer.scrollLeft;
|
||||||
pos.left += renderer.$gutterLayer.gutterWidth;
|
pos.left += renderer.gutterWidth;
|
||||||
|
|
||||||
this.popup.show(pos, lineHeight);
|
this.popup.show(pos, lineHeight);
|
||||||
} else if (keepPopupPosition && !prefix) {
|
} else if (keepPopupPosition && !prefix) {
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,10 @@ var baseStyles = require("../requirejs/text!./static.css");
|
||||||
var config = require("../config");
|
var config = require("../config");
|
||||||
var dom = require("../lib/dom");
|
var dom = require("../lib/dom");
|
||||||
|
|
||||||
|
var SimpleTextLayer = function() {
|
||||||
|
this.config = {};
|
||||||
|
};
|
||||||
|
SimpleTextLayer.prototype = TextLayer.prototype;
|
||||||
|
|
||||||
var highlight = function(el, opts, callback) {
|
var highlight = function(el, opts, callback) {
|
||||||
var m = el.className.match(/lang-(\w+)/);
|
var m = el.className.match(/lang-(\w+)/);
|
||||||
|
|
@ -149,12 +153,8 @@ highlight.renderSync = function(input, mode, theme, lineStart, disableGutter) {
|
||||||
session.setUseWorker(false);
|
session.setUseWorker(false);
|
||||||
session.setMode(mode);
|
session.setMode(mode);
|
||||||
|
|
||||||
var textLayer = new TextLayer(document.createElement("div"));
|
var textLayer = new SimpleTextLayer();
|
||||||
textLayer.setSession(session);
|
textLayer.setSession(session);
|
||||||
textLayer.config = {
|
|
||||||
characterWidth: 10,
|
|
||||||
lineHeight: 20
|
|
||||||
};
|
|
||||||
|
|
||||||
session.setValue(input);
|
session.setValue(input);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,11 @@ exports.toggleCssClass = function(el, name) {
|
||||||
return add;
|
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
|
* Add or remove a CSS class from the list of classes on the given node
|
||||||
* depending on the value of <tt>include</tt>
|
* 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) {
|
if (window.pageYOffset !== undefined) {
|
||||||
exports.getPageScrollTop = function() {
|
exports.getPageScrollTop = function() {
|
||||||
return window.pageYOffset;
|
return window.pageYOffset;
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ function onMouseDown(e) {
|
||||||
var selectionMode;
|
var selectionMode;
|
||||||
if (editor.$mouseHandler.$enableJumpToDef) {
|
if (editor.$mouseHandler.$enableJumpToDef) {
|
||||||
if (ctrl && alt || accel && alt)
|
if (ctrl && alt || accel && alt)
|
||||||
selectionMode = "add";
|
selectionMode = shift ? "block" : "add";
|
||||||
else if (alt && editor.$blockSelectEnabled)
|
else if (alt && editor.$blockSelectEnabled)
|
||||||
selectionMode = "block";
|
selectionMode = "block";
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -117,7 +117,7 @@ function onMouseDown(e) {
|
||||||
|
|
||||||
if (shift) {
|
if (shift) {
|
||||||
oldRange = null;
|
oldRange = null;
|
||||||
range = selection.ranges[0];
|
range = selection.ranges[0] || range;
|
||||||
editor.removeSelectionMarker(range);
|
editor.removeSelectionMarker(range);
|
||||||
}
|
}
|
||||||
editor.once("mouseup", function() {
|
editor.once("mouseup", function() {
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ http.createServer(function(req, res) {
|
||||||
if (req.method == "PUT") {
|
if (req.method == "PUT") {
|
||||||
if (!allowSave)
|
if (!allowSave)
|
||||||
return error(res, 404, "Saving not allowed pass --allow-save to enable");
|
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) {
|
fs.exists(filename, function(exists) {
|
||||||
|
|
@ -86,6 +86,7 @@ function save(req, res, filePath) {
|
||||||
}
|
}
|
||||||
res.statusCode = 200;
|
res.statusCode = 200;
|
||||||
res.end("OK");
|
res.end("OK");
|
||||||
|
console.log("saved ", filePath);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
105
tool/lib.js
105
tool/lib.js
|
|
@ -14,8 +14,16 @@ exports.parsePlist = function(xmlOrJSON, callback) {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
xmlOrJSON = xmlOrJSON.replace(/^\s*\/\/.*/gm, "");
|
xmlOrJSON = xmlOrJSON.replace(
|
||||||
json = JSON.parse(xmlOrJSON)
|
/("(?:\\.|[^"])*")|(?:,\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) {
|
} catch(e) {
|
||||||
json = cson.parse(xmlOrJSON);
|
json = cson.parse(xmlOrJSON);
|
||||||
}
|
}
|
||||||
|
|
@ -24,10 +32,101 @@ exports.parsePlist = function(xmlOrJSON, callback) {
|
||||||
return json;
|
return json;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
exports.formatJSON = function(object, initialIndent) {
|
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) {
|
exports.fillTemplate = function(template, replacements) {
|
||||||
return template.replace(/%(.+?)%/g, function(str, m) {
|
return template.replace(/%(.+?)%/g, function(str, m) {
|
||||||
|
|
|
||||||
|
|
@ -126,8 +126,8 @@ function handleSaveResult(err, editor) {
|
||||||
return log(
|
return log(
|
||||||
"Write access to this file is disabled.\n"+
|
"Write access to this file is disabled.\n"+
|
||||||
"To enable saving your changes to disk, clone the Ace repository\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"+
|
"and run the included web server with the --allow-save option\n"+
|
||||||
"`node static.js --allow-write` or `static.py --puttable=*`"
|
"`node static.js --allow-save` or `static.py --puttable=*`"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
editor.session.getUndoManager().markClean();
|
editor.session.getUndoManager().markClean();
|
||||||
|
|
|
||||||
|
|
@ -662,10 +662,10 @@ function convertTmLanguage(name, langStr) {
|
||||||
|
|
||||||
var languageHighlightRules = lib.fillTemplate(modeHighlightTemplate, {
|
var languageHighlightRules = lib.fillTemplate(modeHighlightTemplate, {
|
||||||
language: languageNameSanitized,
|
language: languageNameSanitized,
|
||||||
languageTokens: lib.formatJSON(patterns, " ").trim(),
|
languageTokens: lib.formatJS(patterns, " ").trim(),
|
||||||
uuid: language.uuid,
|
uuid: language.uuid,
|
||||||
name: name,
|
name: name,
|
||||||
metaData: lib.formatJSON(language, " ").trim()
|
metaData: lib.formatJS(language, "").trim()
|
||||||
});
|
});
|
||||||
|
|
||||||
if (devMode) {
|
if (devMode) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue