1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-04-04 18:33:36 +02:00

Death to E4X and stuff.

This commit is contained in:
Kris Maglione
2012-11-28 18:35:19 -08:00
parent ce51debcdc
commit 9420c58772
3 changed files with 48 additions and 48 deletions

View File

@@ -1397,8 +1397,8 @@ var CommandLine = Module("commandline", {
substring = substring.substr(value.length); substring = substring.substr(value.length);
this.removeSubstring = substring; this.removeSubstring = substring;
let node = DOM.fromXML(<span highlight="Preview">{substring}</span>, let node = DOM.fromJSON(["span", { highlight: "Preview" }, substring],
document); document);
this.withSavedValues(["caret"], function () { this.withSavedValues(["caret"], function () {
this.editor.insertNode(node, this.editor.rootElement, 1); this.editor.insertNode(node, this.editor.rootElement, 1);
@@ -1889,19 +1889,18 @@ var ItemList = Class("ItemList", {
DOM(this.win).resize(this._onResize.closure.tell); DOM(this.win).resize(this._onResize.closure.tell);
}, },
get rootXML() <e4x> get rootXML()
<div highlight="Normal" style="white-space: nowrap" key="root"> ["div", { highlight: "Normal", style: "white-space: nowrap", key: "root" },
<div key="wrapper"> ["div", { key: "wrapper" },
<div highlight="Completions" key="noCompletions"><span highlight="Title">{_("completion.noCompletions")}</span></div> ["div", { highlight: "Completions", key: "noCompletions" },
<div key="completions"/> ["span", { highlight: "Title" },
</div> _("completion.noCompletions")]],
["div", { key: "completions" }]],
<div highlight="Completions">{ ["div", { highlight: "Completions" },
template.map(util.range(0, options["maxitems"] * 2), function (i) template_.map(util.range(0, options["maxitems"] * 2), function (i)
<div highlight="CompItem NonText"><li>~</li></div>) ["div", { highlight: "CompItem NonText" },
}</div> "~"])]],
</div>
</e4x>.elements(),
get itemCount() this.context.contextList.reduce(function (acc, ctxt) acc + ctxt.items.length, 0), get itemCount() this.context.contextList.reduce(function (acc, ctxt) acc + ctxt.items.length, 0),
@@ -2225,21 +2224,19 @@ var ItemList = Class("ItemList", {
}, },
get rootXML() get rootXML()
<div key="root" highlight="CompGroup"> ["div", { key: "root", highlight: "CompGroup" },
<div highlight="Completions"> ["div", { highlight: "Completions" },
{ this.context.createRow(this.context.title || [], "CompTitle") } this.context.createRow(this.context.title || [], "CompTitle")],
</div> ["div", { highlight: "CompTitleSep" }],
<div highlight="CompTitleSep"/> ["div", { key: "contents" },
<div key="contents"> ["div", { key: "up", highlight: "CompLess" }],
<div key="up" highlight="CompLess"/> ["div", { key: "message", highlight: "CompMsg" },
<div key="message" highlight="CompMsg">{this.context.message}</div> this.context.message || []],
<div key="itemsContainer" class="completion-items-container"> ["div", { key: "itemsContainer", class: "completion-items-container" },
<div key="items" highlight="Completions"/> ["div", { key: "items", highlight: "Completions" }]],
</div> ["div", { key: "waiting", highlight: "CompMsg" },
<div key="waiting" highlight="CompMsg">{ItemList.WAITING_MESSAGE}</div> ItemList.WAITING_MESSAGE],
<div key="down" highlight="CompMore"/> ["div", { key: "down", highlight: "CompMore" }]]],
</div>
</div>,
get doc() this.parent.doc, get doc() this.parent.doc,
get win() this.parent.win, get win() this.parent.win,
@@ -2281,7 +2278,7 @@ var ItemList = Class("ItemList", {
this.nodes = {}; this.nodes = {};
this.generatedRange = ItemList.Range(0, 0); this.generatedRange = ItemList.Range(0, 0);
DOM.fromXML(this.rootXML, this.doc, this.nodes); DOM.fromJSON(this.rootXML, this.doc, this.nodes);
}, },
/** /**
@@ -2292,7 +2289,8 @@ var ItemList = Class("ItemList", {
DOM(this.nodes.items).empty(); DOM(this.nodes.items).empty();
if (this.context.message) if (this.context.message)
DOM(this.nodes.message).empty().append(<>{this.context.message}</>); DOM(this.nodes.message).empty()
.append(DOM.fromJSON(this.context.message, this.doc));
if (!this.selectedIdx > this.itemCount) if (!this.selectedIdx > this.itemCount)
this.selectedIdx = null; this.selectedIdx = null;

View File

@@ -2,7 +2,7 @@
// //
// This work is licensed for reuse under an MIT license. Details are // This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file. // given in the LICENSE.txt file included with this file.
/* use strict */ "use strict";
let { getOwnPropertyNames } = Object; let { getOwnPropertyNames } = Object;
@@ -13,7 +13,7 @@ defineModule("javascript", {
require: ["util"] require: ["util"]
}); });
lazyRequire("template", ["template"]); lazyRequire("template", ["template", "template_"]);
let isPrototypeOf = Object.prototype.isPrototypeOf; let isPrototypeOf = Object.prototype.isPrototypeOf;
@@ -489,10 +489,10 @@ var JavaScript = Module("javascript", {
if (callable(func)) { if (callable(func)) {
let [, prefix, args] = /^(function .*?)\((.*?)\)/.exec(Function.prototype.toString.call(func)); let [, prefix, args] = /^(function .*?)\((.*?)\)/.exec(Function.prototype.toString.call(func));
let n = this._get(i).comma.length; let n = this._get(i).comma.length;
args = template.map(Iterator(args.split(", ")), args = template_.map(Iterator(args.split(", ")),
function ([i, arg]) <span highlight={i == n ? "Filter" : ""}>{arg}</span>, function ([i, arg]) ["span", { highlight: i == n ? "Filter" : "" }, arg],
<>,&#xa0;</>); ",\u00a0");
this.context.message = <>{prefix}({args})</>; this.context.message = ["", prefix + "(", args, ")"];
} }
} }
} }
@@ -596,8 +596,8 @@ var JavaScript = Module("javascript", {
if (!this.context.tabPressed && key == "" && obj.length > 1) { if (!this.context.tabPressed && key == "" && obj.length > 1) {
let message = this.context.message || ""; let message = this.context.message || "";
this.context.waitingForTab = true; this.context.waitingForTab = true;
this.context.message = <>{message} this.context.message = ["", message, "\n",
{_("completion.waitingForKeyPress")}</>; _("completion.waitingForKeyPress")];
return null; return null;
} }
@@ -716,7 +716,6 @@ var JavaScript = Module("javascript", {
}, },
addOutput: function addOutput(js) { addOutput: function addOutput(js) {
default xml namespace = XHTML;
this.count++; this.count++;
try { try {
@@ -729,19 +728,21 @@ var JavaScript = Module("javascript", {
if (e.fileName) if (e.fileName)
e = util.fixURI(e.fileName) + ":" + e.lineNumber + ": " + e; e = util.fixURI(e.fileName) + ":" + e.lineNumber + ": " + e;
xml = <span highlight="ErrorMsg">{e}</span>; xml = ["span", { highlight: "ErrorMsg" }, e];
} }
let prompt = "js" + this.count; let prompt = "js" + this.count;
Class.replaceProperty(this.context, prompt, result); Class.replaceProperty(this.context, prompt, result);
XML.ignoreWhitespace = XML.prettyPrinting = false;
let nodes = {}; let nodes = {};
this.rootNode.appendChild( this.rootNode.appendChild(
util.xmlToDom(<e4x> DOM.fromJSON(
<div highlight="REPL-E" key="e"><span highlight="REPL-R">{prompt}></span> {js}</div> [["div", { highlight: "REPL-E", key: "e" },
<div highlight="REPL-P" key="p">{xml}</div> ["span", { highlight: "REPL-R" },
</e4x>.elements(), this.document, nodes)); prompt, ">"], " ", js],
["div", { highlight: "REPL-P", key: "p" },
xml]],
this.document, nodes));
this.rootNode.scrollTop += nodes.e.getBoundingClientRect().top this.rootNode.scrollTop += nodes.e.getBoundingClientRect().top
- this.rootNode.getBoundingClientRect().top; - this.rootNode.getBoundingClientRect().top;
@@ -750,7 +751,6 @@ var JavaScript = Module("javascript", {
count: 0, count: 0,
message: Class.Memoize(function () { message: Class.Memoize(function () {
default xml namespace = XHTML;
DOM.fromJSON(["div", { highlight: "REPL", key: "rootNode" }], DOM.fromJSON(["div", { highlight: "REPL", key: "rootNode" }],
this.document, this); this.document, this);

View File

@@ -1024,7 +1024,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
return color ? <div style="white-space: pre-wrap;">{string}</div> : [s for each (s in string)].join(""); return color ? <div style="white-space: pre-wrap;">{string}</div> : [s for each (s in string)].join("");
}, },
prettifyJSON: function prettifyJSON(data, indent) { prettifyJSON: function prettifyJSON(data, indent, invalidOK) {
const INDENT = indent || " "; const INDENT = indent || " ";
function rec(data, level, seen) { function rec(data, level, seen) {
@@ -1072,6 +1072,8 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
else else
res[res.length - 1] = "{}"; res[res.length - 1] = "{}";
} }
else if (invalidOK)
res.push({}.toString.call(data));
else else
throw Error("Invalid JSON object"); throw Error("Invalid JSON object");
} }