Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
ca8da0a3f3
20 changed files with 225 additions and 73 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) {
|
||||||
|
|
|
||||||
|
|
@ -423,6 +423,12 @@ exports.commands = [{
|
||||||
exec: function() {},
|
exec: function() {},
|
||||||
passEvent: true,
|
passEvent: true,
|
||||||
readOnly: true
|
readOnly: true
|
||||||
|
}, {
|
||||||
|
name: "copy",
|
||||||
|
exec: function(editor) {
|
||||||
|
// placeholder for replay macro
|
||||||
|
},
|
||||||
|
readOnly: true
|
||||||
},
|
},
|
||||||
|
|
||||||
// commands disabled in readOnly mode
|
// commands disabled in readOnly mode
|
||||||
|
|
@ -439,6 +445,12 @@ exports.commands = [{
|
||||||
},
|
},
|
||||||
scrollIntoView: "cursor",
|
scrollIntoView: "cursor",
|
||||||
multiSelectAction: "forEach"
|
multiSelectAction: "forEach"
|
||||||
|
}, {
|
||||||
|
name: "paste",
|
||||||
|
exec: function(editor, args) {
|
||||||
|
editor.$handlePaste(args);
|
||||||
|
},
|
||||||
|
scrollIntoView: "cursor"
|
||||||
}, {
|
}, {
|
||||||
name: "removeline",
|
name: "removeline",
|
||||||
bindKey: bindKey("Ctrl-D", "Command-D"),
|
bindKey: bindKey("Ctrl-D", "Command-D"),
|
||||||
|
|
|
||||||
|
|
@ -916,13 +916,15 @@ var Editor = function(renderer, session) {
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
this.onPaste = function(text, event) {
|
this.onPaste = function(text, event) {
|
||||||
// todo this should change when paste becomes a command
|
|
||||||
if (this.$readOnly)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var e = {text: text, event: event};
|
var e = {text: text, event: event};
|
||||||
|
this.commands.exec("paste", this, e);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.$handlePaste = function(e) {
|
||||||
|
if (typeof e == "string")
|
||||||
|
e = {text: e};
|
||||||
this._signal("paste", e);
|
this._signal("paste", e);
|
||||||
text = e.text;
|
var text = e.text;
|
||||||
if (!this.inMultiSelectMode || this.inVirtualSelectionMode) {
|
if (!this.inMultiSelectMode || this.inVirtualSelectionMode) {
|
||||||
this.insert(text);
|
this.insert(text);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -940,7 +942,6 @@ var Editor = function(renderer, session) {
|
||||||
this.session.insert(range.start, lines[i]);
|
this.session.insert(range.start, lines[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.renderer.scrollCursorIntoView();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.execCommand = function(command, args) {
|
this.execCommand = function(command, args) {
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,7 @@ var supportedModes = {
|
||||||
Pascal: ["pas|p"],
|
Pascal: ["pas|p"],
|
||||||
Perl: ["pl|pm"],
|
Perl: ["pl|pm"],
|
||||||
pgSQL: ["pgsql"],
|
pgSQL: ["pgsql"],
|
||||||
PHP: ["php|phtml"],
|
PHP: ["php|phtml|shtml|php3|php4|php5|phps|phpt|aw|ctp"],
|
||||||
Powershell: ["ps1"],
|
Powershell: ["ps1"],
|
||||||
Praat: ["praat|praatscript|psc|proc"],
|
Praat: ["praat|praatscript|psc|proc"],
|
||||||
Prolog: ["plg|prolog"],
|
Prolog: ["plg|prolog"],
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ var Text = function(parentEl) {
|
||||||
this.EOL_CHAR_LF = "\xAC";
|
this.EOL_CHAR_LF = "\xAC";
|
||||||
this.EOL_CHAR_CRLF = "\xa4";
|
this.EOL_CHAR_CRLF = "\xa4";
|
||||||
this.EOL_CHAR = this.EOL_CHAR_LF;
|
this.EOL_CHAR = this.EOL_CHAR_LF;
|
||||||
this.TAB_CHAR = "\u2192"; //"\u21E5";
|
this.TAB_CHAR = "\u2014"; //"\u21E5";
|
||||||
this.SPACE_CHAR = "\xB7";
|
this.SPACE_CHAR = "\xB7";
|
||||||
this.$padding = 0;
|
this.$padding = 0;
|
||||||
|
|
||||||
|
|
@ -128,8 +128,7 @@ var Text = function(parentEl) {
|
||||||
for (var i = 1; i < tabSize + 1; i++) {
|
for (var i = 1; i < tabSize + 1; i++) {
|
||||||
if (this.showInvisibles) {
|
if (this.showInvisibles) {
|
||||||
tabStr.push("<span class='ace_invisible ace_invisible_tab'>"
|
tabStr.push("<span class='ace_invisible ace_invisible_tab'>"
|
||||||
+ this.TAB_CHAR
|
+ lang.stringRepeat(this.TAB_CHAR, i)
|
||||||
+ lang.stringRepeat(" ", i - 1)
|
|
||||||
+ "</span>");
|
+ "</span>");
|
||||||
} else {
|
} else {
|
||||||
tabStr.push(lang.stringRepeat(" ", i));
|
tabStr.push(lang.stringRepeat(" ", i));
|
||||||
|
|
@ -145,7 +144,7 @@ var Text = function(parentEl) {
|
||||||
spaceClass = " ace_invisible_space";
|
spaceClass = " ace_invisible_space";
|
||||||
tabClass = " ace_invisible_tab";
|
tabClass = " ace_invisible_tab";
|
||||||
var spaceContent = lang.stringRepeat(this.SPACE_CHAR, this.tabSize);
|
var spaceContent = lang.stringRepeat(this.SPACE_CHAR, this.tabSize);
|
||||||
var tabContent = this.TAB_CHAR + lang.stringRepeat(" ", this.tabSize - 1);
|
var tabContent = lang.stringRepeat(this.TAB_CHAR, this.tabSize);
|
||||||
} else{
|
} else{
|
||||||
var spaceContent = lang.stringRepeat(" ", this.tabSize);
|
var spaceContent = lang.stringRepeat(" ", this.tabSize);
|
||||||
var tabContent = spaceContent;
|
var tabContent = spaceContent;
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ module.exports = {
|
||||||
var EOL = "<span class='ace_invisible ace_invisible_eol'>" + textLayer.EOL_CHAR + "</span>";
|
var EOL = "<span class='ace_invisible ace_invisible_eol'>" + textLayer.EOL_CHAR + "</span>";
|
||||||
var SPACE = function(i) {return Array(i+1).join(" ")}
|
var SPACE = function(i) {return Array(i+1).join(" ")}
|
||||||
var DOT = function(i) {return Array(i+1).join(textLayer.SPACE_CHAR)}
|
var DOT = function(i) {return Array(i+1).join(textLayer.SPACE_CHAR)}
|
||||||
var TAB = function(i) {return textLayer.TAB_CHAR + SPACE(i-1)}
|
var TAB = function(i) {return Array(i+1).join(textLayer.TAB_CHAR)}
|
||||||
function testRender(results) {
|
function testRender(results) {
|
||||||
for (var i = results.length; i--; ) {
|
for (var i = results.length; i--; ) {
|
||||||
var stringBuilder = [];
|
var stringBuilder = [];
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -144,6 +144,16 @@ module.exports = {
|
||||||
exec("selectleft", 1);
|
exec("selectleft", 1);
|
||||||
exec("insertstring", 1, '"');
|
exec("insertstring", 1, '"');
|
||||||
assert.equal(editor.getValue(), '("foo")');
|
assert.equal(editor.getValue(), '("foo")');
|
||||||
|
|
||||||
|
editor.setValue("", 1);
|
||||||
|
exec("selectleft", 1);
|
||||||
|
exec("insertstring", 1, '"');
|
||||||
|
assert.equal(editor.getValue(), '""');
|
||||||
|
exec("insertstring", 1, '\\');
|
||||||
|
exec("insertstring", 1, 'n');
|
||||||
|
exec("insertstring", 1, '"');
|
||||||
|
assert.equal(editor.getValue(), '"\\n"');
|
||||||
|
|
||||||
},
|
},
|
||||||
"test: xml": function() {
|
"test: xml": function() {
|
||||||
editor = new Editor(new MockRenderer());
|
editor = new Editor(new MockRenderer());
|
||||||
|
|
|
||||||
|
|
@ -269,8 +269,8 @@ var CstyleBehaviour = function() {
|
||||||
if (leftChar == "\\" && token && /escape/.test(token.type))
|
if (leftChar == "\\" && token && /escape/.test(token.type))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var stringBefore = token && /string/.test(token.type);
|
var stringBefore = token && /string|escape/.test(token.type);
|
||||||
var stringAfter = !rightToken || /string/.test(rightToken.type);
|
var stringAfter = !rightToken || /string|escape/.test(rightToken.type);
|
||||||
|
|
||||||
var pair;
|
var pair;
|
||||||
if (rightChar == quote) {
|
if (rightChar == quote) {
|
||||||
|
|
|
||||||
|
|
@ -14,14 +14,13 @@ var Mode = function() {
|
||||||
this.HighlightRules = HandlebarsHighlightRules;
|
this.HighlightRules = HandlebarsHighlightRules;
|
||||||
this.$behaviour = new HtmlBehaviour();
|
this.$behaviour = new HtmlBehaviour();
|
||||||
|
|
||||||
|
|
||||||
this.foldingRules = new HtmlFoldMode();
|
this.foldingRules = new HtmlFoldMode();
|
||||||
};
|
};
|
||||||
|
|
||||||
oop.inherits(Mode, HtmlMode);
|
oop.inherits(Mode, HtmlMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
this.blockComment = {start: "{!--", end: "--}"};
|
this.blockComment = {start: "{{!--", end: "--}}"};
|
||||||
this.$id = "ace/mode/handlebars";
|
this.$id = "ace/mode/handlebars";
|
||||||
}).call(Mode.prototype);
|
}).call(Mode.prototype);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -231,7 +231,7 @@ var LessHighlightRules = function() {
|
||||||
regex: "\\.[a-z0-9-_]+"
|
regex: "\\.[a-z0-9-_]+"
|
||||||
}, {
|
}, {
|
||||||
token: "variable.language",
|
token: "variable.language",
|
||||||
regex: ":[a-z0-9-_]+"
|
regex: ":[a-z_][a-z0-9-_]*"
|
||||||
}, {
|
}, {
|
||||||
token: "constant",
|
token: "constant",
|
||||||
regex: "[a-z0-9-_]+"
|
regex: "[a-z0-9-_]+"
|
||||||
|
|
|
||||||
|
|
@ -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() {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
"no use strict";
|
"no use strict";
|
||||||
;(function(window) {
|
;(function(window) {
|
||||||
if (typeof window.window != "undefined" && window.document) {
|
if (typeof window.window != "undefined" && window.document)
|
||||||
|
return;
|
||||||
|
if (window.require && window.define)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
window.console = function() {
|
window.console = function() {
|
||||||
var msgs = Array.prototype.slice.call(arguments, 0);
|
var msgs = Array.prototype.slice.call(arguments, 0);
|
||||||
|
|
@ -19,6 +20,7 @@ window.ace = window;
|
||||||
window.onerror = function(message, file, line, col, err) {
|
window.onerror = function(message, file, line, col, err) {
|
||||||
postMessage({type: "error", data: {
|
postMessage({type: "error", data: {
|
||||||
message: message,
|
message: message,
|
||||||
|
data: err.data,
|
||||||
file: file,
|
file: file,
|
||||||
line: line,
|
line: line,
|
||||||
col: col,
|
col: col,
|
||||||
|
|
@ -37,7 +39,7 @@ window.normalizeModule = function(parentId, moduleName) {
|
||||||
var base = parentId.split("/").slice(0, -1).join("/");
|
var base = parentId.split("/").slice(0, -1).join("/");
|
||||||
moduleName = (base ? base + "/" : "") + moduleName;
|
moduleName = (base ? base + "/" : "") + moduleName;
|
||||||
|
|
||||||
while(moduleName.indexOf(".") !== -1 && previous != moduleName) {
|
while (moduleName.indexOf(".") !== -1 && previous != moduleName) {
|
||||||
var previous = moduleName;
|
var previous = moduleName;
|
||||||
moduleName = moduleName.replace(/^\.\//, "").replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
|
moduleName = moduleName.replace(/^\.\//, "").replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
|
||||||
}
|
}
|
||||||
|
|
@ -46,7 +48,7 @@ window.normalizeModule = function(parentId, moduleName) {
|
||||||
return moduleName;
|
return moduleName;
|
||||||
};
|
};
|
||||||
|
|
||||||
window.require = function(parentId, id) {
|
window.require = function require(parentId, id) {
|
||||||
if (!id) {
|
if (!id) {
|
||||||
id = parentId;
|
id = parentId;
|
||||||
parentId = null;
|
parentId = null;
|
||||||
|
|
@ -65,16 +67,35 @@ window.require = function(parentId, id) {
|
||||||
return module.exports;
|
return module.exports;
|
||||||
}
|
}
|
||||||
|
|
||||||
var chunks = id.split("/");
|
|
||||||
if (!window.require.tlns)
|
if (!window.require.tlns)
|
||||||
return console.log("unable to load " + id);
|
return console.log("unable to load " + id);
|
||||||
chunks[0] = window.require.tlns[chunks[0]] || chunks[0];
|
|
||||||
var path = chunks.join("/") + ".js";
|
var path = resolveModuleId(id, window.require.tlns);
|
||||||
|
if (path.slice(-3) != ".js") path += ".js";
|
||||||
|
|
||||||
window.require.id = id;
|
window.require.id = id;
|
||||||
|
window.require.modules[id] = {}; // prevent infinite loop on broken modules
|
||||||
importScripts(path);
|
importScripts(path);
|
||||||
return window.require(parentId, id);
|
return window.require(parentId, id);
|
||||||
};
|
};
|
||||||
|
function resolveModuleId(id, paths) {
|
||||||
|
var testPath = id, tail = "";
|
||||||
|
while (testPath) {
|
||||||
|
var alias = paths[testPath];
|
||||||
|
if (typeof alias == "string") {
|
||||||
|
return alias + tail;
|
||||||
|
} else if (alias) {
|
||||||
|
return alias.location.replace(/\/*$/, "/") + (tail || alias.main || alias.name);
|
||||||
|
} else if (alias === false) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
var i = testPath.lastIndexOf("/");
|
||||||
|
if (i === -1) break;
|
||||||
|
tail = testPath.substr(i) + tail;
|
||||||
|
testPath = testPath.slice(0, i);
|
||||||
|
}
|
||||||
|
return id;
|
||||||
|
}
|
||||||
window.require.modules = {};
|
window.require.modules = {};
|
||||||
window.require.tlns = {};
|
window.require.tlns = {};
|
||||||
|
|
||||||
|
|
@ -100,9 +121,9 @@ window.define = function(id, deps, factory) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!deps.length)
|
if (!deps.length)
|
||||||
// If there is no dependencies, we inject 'require', 'exports' and
|
// If there is no dependencies, we inject "require", "exports" and
|
||||||
// 'module' as dependencies, to provide CommonJS compatibility.
|
// "module" as dependencies, to provide CommonJS compatibility.
|
||||||
deps = ['require', 'exports', 'module'];
|
deps = ["require", "exports", "module"];
|
||||||
|
|
||||||
var req = function(childId) {
|
var req = function(childId) {
|
||||||
return window.require(id, childId);
|
return window.require(id, childId);
|
||||||
|
|
@ -113,16 +134,16 @@ window.define = function(id, deps, factory) {
|
||||||
factory: function() {
|
factory: function() {
|
||||||
var module = this;
|
var module = this;
|
||||||
var returnExports = factory.apply(this, deps.map(function(dep) {
|
var returnExports = factory.apply(this, deps.map(function(dep) {
|
||||||
switch(dep) {
|
switch (dep) {
|
||||||
// Because 'require', 'exports' and 'module' aren't actual
|
// Because "require", "exports" and "module" aren't actual
|
||||||
// dependencies, we must handle them seperately.
|
// dependencies, we must handle them seperately.
|
||||||
case 'require': return req;
|
case "require": return req;
|
||||||
case 'exports': return module.exports;
|
case "exports": return module.exports;
|
||||||
case 'module': return module;
|
case "module": return module;
|
||||||
// But for all other dependencies, we can just go ahead and
|
// But for all other dependencies, we can just go ahead and
|
||||||
// require them.
|
// require them.
|
||||||
default: return req(dep);
|
default: return req(dep);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
if (returnExports)
|
if (returnExports)
|
||||||
module.exports = returnExports;
|
module.exports = returnExports;
|
||||||
|
|
@ -131,9 +152,10 @@ window.define = function(id, deps, factory) {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
window.define.amd = {};
|
window.define.amd = {};
|
||||||
|
require.tlns = {};
|
||||||
window.initBaseUrls = function initBaseUrls(topLevelNamespaces) {
|
window.initBaseUrls = function initBaseUrls(topLevelNamespaces) {
|
||||||
require.tlns = topLevelNamespaces;
|
for (var i in topLevelNamespaces)
|
||||||
|
require.tlns[i] = topLevelNamespaces[i];
|
||||||
};
|
};
|
||||||
|
|
||||||
window.initSender = function initSender() {
|
window.initSender = function initSender() {
|
||||||
|
|
@ -173,21 +195,23 @@ var sender = window.sender = null;
|
||||||
|
|
||||||
window.onmessage = function(e) {
|
window.onmessage = function(e) {
|
||||||
var msg = e.data;
|
var msg = e.data;
|
||||||
if (msg.command) {
|
if (msg.event && sender) {
|
||||||
|
sender._signal(msg.event, msg.data);
|
||||||
|
}
|
||||||
|
else if (msg.command) {
|
||||||
if (main[msg.command])
|
if (main[msg.command])
|
||||||
main[msg.command].apply(main, msg.args);
|
main[msg.command].apply(main, msg.args);
|
||||||
|
else if (window[msg.command])
|
||||||
|
window[msg.command].apply(window, msg.args);
|
||||||
else
|
else
|
||||||
throw new Error("Unknown command:" + msg.command);
|
throw new Error("Unknown command:" + msg.command);
|
||||||
}
|
}
|
||||||
else if (msg.init) {
|
else if (msg.init) {
|
||||||
initBaseUrls(msg.tlns);
|
window.initBaseUrls(msg.tlns);
|
||||||
require("ace/lib/es5-shim");
|
require("ace/lib/es5-shim");
|
||||||
sender = window.sender = initSender();
|
sender = window.sender = window.initSender();
|
||||||
var clazz = require(msg.module)[msg.classname];
|
var clazz = require(msg.module)[msg.classname];
|
||||||
main = window.main = new clazz(sender);
|
main = window.main = new clazz(sender);
|
||||||
}
|
}
|
||||||
else if (msg.event && sender) {
|
|
||||||
sender._signal(msg.event, msg.data);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
})(this);
|
})(this);
|
||||||
|
|
@ -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