1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-09 20:07:35 +01: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);
this.removeSubstring = substring;
let node = DOM.fromXML(<span highlight="Preview">{substring}</span>,
document);
let node = DOM.fromJSON(["span", { highlight: "Preview" }, substring],
document);
this.withSavedValues(["caret"], function () {
this.editor.insertNode(node, this.editor.rootElement, 1);
@@ -1889,19 +1889,18 @@ var ItemList = Class("ItemList", {
DOM(this.win).resize(this._onResize.closure.tell);
},
get rootXML() <e4x>
<div highlight="Normal" style="white-space: nowrap" key="root">
<div key="wrapper">
<div highlight="Completions" key="noCompletions"><span highlight="Title">{_("completion.noCompletions")}</span></div>
<div key="completions"/>
</div>
get rootXML()
["div", { highlight: "Normal", style: "white-space: nowrap", key: "root" },
["div", { key: "wrapper" },
["div", { highlight: "Completions", key: "noCompletions" },
["span", { highlight: "Title" },
_("completion.noCompletions")]],
["div", { key: "completions" }]],
<div highlight="Completions">{
template.map(util.range(0, options["maxitems"] * 2), function (i)
<div highlight="CompItem NonText"><li>~</li></div>)
}</div>
</div>
</e4x>.elements(),
["div", { highlight: "Completions" },
template_.map(util.range(0, options["maxitems"] * 2), function (i)
["div", { highlight: "CompItem NonText" },
"~"])]],
get itemCount() this.context.contextList.reduce(function (acc, ctxt) acc + ctxt.items.length, 0),
@@ -2225,21 +2224,19 @@ var ItemList = Class("ItemList", {
},
get rootXML()
<div key="root" highlight="CompGroup">
<div highlight="Completions">
{ this.context.createRow(this.context.title || [], "CompTitle") }
</div>
<div highlight="CompTitleSep"/>
<div key="contents">
<div key="up" highlight="CompLess"/>
<div key="message" highlight="CompMsg">{this.context.message}</div>
<div key="itemsContainer" class="completion-items-container">
<div key="items" highlight="Completions"/>
</div>
<div key="waiting" highlight="CompMsg">{ItemList.WAITING_MESSAGE}</div>
<div key="down" highlight="CompMore"/>
</div>
</div>,
["div", { key: "root", highlight: "CompGroup" },
["div", { highlight: "Completions" },
this.context.createRow(this.context.title || [], "CompTitle")],
["div", { highlight: "CompTitleSep" }],
["div", { key: "contents" },
["div", { key: "up", highlight: "CompLess" }],
["div", { key: "message", highlight: "CompMsg" },
this.context.message || []],
["div", { key: "itemsContainer", class: "completion-items-container" },
["div", { key: "items", highlight: "Completions" }]],
["div", { key: "waiting", highlight: "CompMsg" },
ItemList.WAITING_MESSAGE],
["div", { key: "down", highlight: "CompMore" }]]],
get doc() this.parent.doc,
get win() this.parent.win,
@@ -2281,7 +2278,7 @@ var ItemList = Class("ItemList", {
this.nodes = {};
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();
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)
this.selectedIdx = null;

View File

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