mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-22 00:07:58 +01:00
Death to E4X and stuff.
This commit is contained in:
@@ -10,8 +10,9 @@ defineModule("completion", {
|
||||
exports: ["CompletionContext", "Completion", "completion"]
|
||||
}, this);
|
||||
|
||||
lazyRequire("dom", ["DOM"]);
|
||||
lazyRequire("messages", ["_", "messages"]);
|
||||
lazyRequire("template", ["template"]);
|
||||
lazyRequire("template", ["template", "template_"]);
|
||||
|
||||
/**
|
||||
* Creates a new completion context.
|
||||
@@ -654,17 +655,16 @@ var CompletionContext = Class("CompletionContext", {
|
||||
if (cache) {
|
||||
if (idx in this.items && !(idx in this.cache.rows))
|
||||
try {
|
||||
cache[idx] = util.xmlToDom(this.createRow(this.items[idx]),
|
||||
doc || this.doc);
|
||||
cache[idx] = DOM.fromJSON(this.createRow(this.items[idx]),
|
||||
doc || this.doc);
|
||||
}
|
||||
catch (e) {
|
||||
util.reportError(e);
|
||||
XML.ignoreWhitespace = XML.prettyPrinting = false;
|
||||
cache[idx] = util.xmlToDom(
|
||||
<div highlight="CompItem" style="white-space: nowrap">
|
||||
<li highlight="CompResult">{this.text} </li>
|
||||
<li highlight="CompDesc ErrorMsg">{e} </li>
|
||||
</div>, doc || this.doc);
|
||||
cache[idx] = DOM.fromJSON(
|
||||
["div", { highlight: "CompItem", style: "white-space: nowrap" },
|
||||
["li", { highlight: "CompResult" }, this.text + "\u00a0"],
|
||||
["li", { highlight: "CompDesc ErrorMsg" }, e + "\u00a0"]],
|
||||
doc || this.doc);
|
||||
}
|
||||
return cache[idx];
|
||||
}
|
||||
@@ -935,11 +935,10 @@ var Completion = Module("completion", {
|
||||
contexts = context.contextList.slice(-1);
|
||||
|
||||
modules.commandline.commandOutput(
|
||||
<div highlight="Completions">
|
||||
{ template.map(contexts, function (context)
|
||||
template.completionRow(context.title, "CompTitle") +
|
||||
template.map(context.items, function (item) context.createRow(item), null, 100)) }
|
||||
</div>);
|
||||
["div", { highlight: "Completions" },
|
||||
template_.map(contexts, function (context)
|
||||
[template.completionRow(context.title, "CompTitle"),
|
||||
template_.map(context.items, function (item) context.createRow(item), null, 100)])]);
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -1120,10 +1119,10 @@ var Completion = Module("completion", {
|
||||
"List the completion contexts used during completion of an Ex command",
|
||||
function (args) {
|
||||
modules.commandline.commandOutput(
|
||||
<div highlight="Completions">
|
||||
{ template.completionRow(["Context", "Title"], "CompTitle") }
|
||||
{ template.map(completion.contextList || [], function (item) template.completionRow(item, "CompItem")) }
|
||||
</div>);
|
||||
["div", { highlight: "Completions" },
|
||||
template.completionRow(["Context", "Title"], "CompTitle"),
|
||||
template_.map(completion.contextList || [],
|
||||
function (item) template.completionRow(item, "CompItem"))]);
|
||||
},
|
||||
{
|
||||
argCount: "*",
|
||||
|
||||
@@ -10,7 +10,7 @@ defineModule("highlight", {
|
||||
});
|
||||
|
||||
lazyRequire("styles", ["Styles", "styles"]);
|
||||
lazyRequire("template", ["template"]);
|
||||
lazyRequire("template", ["template", "template_"]);
|
||||
|
||||
var Highlight = Struct("class", "selector", "sites",
|
||||
"defaultExtends", "defaultValue",
|
||||
@@ -345,14 +345,14 @@ var Highlights = Module("Highlight", {
|
||||
|
||||
if (!modify)
|
||||
modules.commandline.commandOutput(
|
||||
template.tabular(["Key", "Sample", "Link", "CSS"],
|
||||
template_.tabular(["Key", "Sample", "Link", "CSS"],
|
||||
["padding: 0 1em 0 0; vertical-align: top; max-width: 16em; overflow: hidden;",
|
||||
"text-align: center"],
|
||||
([h.class,
|
||||
<span style={"text-align: center; line-height: 1em;" + h.value + style}>XXX</span>,
|
||||
template.map(h.extends, function (s) template.highlight(s), <>,</>),
|
||||
template.highlightRegexp(h.value, /\b[-\w]+(?=:)|\/\*.*?\*\//g,
|
||||
function (match) <span highlight={match[0] == "/" ? "Comment" : "Key"}>{match}</span>)
|
||||
["span", { style: "text-align: center; line-height: 1em;" + h.value + style }, "XXX"],
|
||||
template_.map(h.extends, function (s) template.highlight(s), ","),
|
||||
template_.highlightRegexp(h.value, /\b[-\w]+(?=:)|\/\*.*?\*\//g,
|
||||
function (match) ["span", { highlight: match[0] == "/" ? "Comment" : "Key" }, match])
|
||||
]
|
||||
for (h in highlight)
|
||||
if (!key || h.class.indexOf(key) > -1))));
|
||||
|
||||
@@ -573,6 +573,56 @@ var Template_ = Module("Template_", {
|
||||
return res;
|
||||
},
|
||||
|
||||
|
||||
highlightFilter: function highlightFilter(str, filter, highlight, isURI) {
|
||||
if (isURI)
|
||||
str = util.losslessDecodeURI(str);
|
||||
|
||||
return this.highlightSubstrings(str, (function () {
|
||||
if (filter.length == 0)
|
||||
return;
|
||||
|
||||
let lcstr = String.toLowerCase(str);
|
||||
let lcfilter = filter.toLowerCase();
|
||||
let start = 0;
|
||||
while ((start = lcstr.indexOf(lcfilter, start)) > -1) {
|
||||
yield [start, filter.length];
|
||||
start += filter.length;
|
||||
}
|
||||
})(), highlight || template.filter);
|
||||
},
|
||||
|
||||
highlightRegexp: function highlightRegexp(str, re, highlight) {
|
||||
return this.highlightSubstrings(str, (function () {
|
||||
for (let res in util.regexp.iterate(re, str))
|
||||
yield [res.index, res[0].length, res.wholeMatch ? [res] : res];
|
||||
})(), highlight || template.filter);
|
||||
},
|
||||
|
||||
highlightSubstrings: function highlightSubstrings(str, iter, highlight) {
|
||||
if (!isString(str))
|
||||
return str;
|
||||
|
||||
if (str == "")
|
||||
return DOM.DOMString(str);
|
||||
|
||||
let s = [""];
|
||||
let start = 0;
|
||||
let n = 0, _i;
|
||||
for (let [i, length, args] in iter) {
|
||||
if (i == _i || i < _i)
|
||||
break;
|
||||
_i = i;
|
||||
|
||||
XML.ignoreWhitespace = false;
|
||||
s.push(str.substring(start, i),
|
||||
highlight.apply(this, Array.concat(args || str.substr(i, length))));
|
||||
start = i + length;
|
||||
}
|
||||
s.push(str.substr(start));
|
||||
return s;
|
||||
},
|
||||
|
||||
table: function table(title, data, indent) {
|
||||
let table = ["table", {},
|
||||
["tr", { highlight: "Title", align: "left" },
|
||||
@@ -585,6 +635,19 @@ var Template_ = Module("Template_", {
|
||||
if (table[3].length)
|
||||
return table;
|
||||
},
|
||||
|
||||
tabular: function tabular(headings, style, iter) {
|
||||
let self = this;
|
||||
// TODO: This might be mind-bogglingly slow. We'll see.
|
||||
return ["table", {},
|
||||
["tr", { highlight: "Title", align: "left" },
|
||||
this.map(headings, function (h)
|
||||
["th", {}, h])],
|
||||
this.map(iter, function (row)
|
||||
["tr", {},
|
||||
self.map(Iterator(row), function ([i, d])
|
||||
["td", { style: style[i] || "" }, d])])];
|
||||
},
|
||||
});
|
||||
|
||||
endModule();
|
||||
|
||||
Reference in New Issue
Block a user