mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-01-09 21:14:13 +01:00
Some string highlighting stuff.
This commit is contained in:
@@ -485,10 +485,9 @@ liberator.registerObserver("load_commands", function ()
|
||||
["padding: 0 1em 0 0; vertical-align: top", "text-align: center"],
|
||||
([h.class,
|
||||
<span style={"text-align: center; line-height: 1em;" + h.value + style}>XXX</span>,
|
||||
template.maybeXML(h.value.replace(/\s+/g, "\u00a0")
|
||||
.replace(/\b([-\w]+):/g, "<span class=\"hl-Filter\">$1:</span>"))]
|
||||
template.highlightRegexp(h.value, /\b[-\w]+(?=:)/g)]
|
||||
for (h in highlight)
|
||||
if (!key || h.class.indexOf(key) > -1)));
|
||||
if (!key || h.class.indexOf(key) > -1)));
|
||||
commandline.echo(str, commandline.HL_NORMAL, commandline.FORCE_MULTILINE);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -76,24 +76,51 @@ const template = {
|
||||
},
|
||||
|
||||
highlightFilter: function (str, filter)
|
||||
{
|
||||
if (typeof str == "xml")
|
||||
return str;
|
||||
|
||||
return this.highlightSubstrings(str, (function ()
|
||||
{
|
||||
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;
|
||||
}
|
||||
})());
|
||||
},
|
||||
|
||||
highlightRegexp: function (str, re)
|
||||
{
|
||||
if (typeof str == "xml")
|
||||
return str;
|
||||
|
||||
return this.highlightSubstrings(str, (function ()
|
||||
{
|
||||
while (res = re.exec(str))
|
||||
yield [res.index, res[0].length];
|
||||
})());
|
||||
},
|
||||
|
||||
highlightSubstrings: function (str, iter)
|
||||
{
|
||||
if (typeof str == "xml")
|
||||
return str;
|
||||
if (str == "")
|
||||
return <>{str}</>;
|
||||
|
||||
let lcstr = String(str).toLowerCase();
|
||||
let lcfilter = filter.toLowerCase();
|
||||
XML.ignoreWhitespace = false;
|
||||
str = String(str).replace(" ", "\u00a0");
|
||||
let s = <></>;
|
||||
let start = 0;
|
||||
let i;
|
||||
while ((i = lcstr.indexOf(lcfilter, start)) > -1)
|
||||
for (let [i, length] in iter)
|
||||
{
|
||||
XML.ignoreWhitespace = false;
|
||||
s += <>{str.substring(start, i)}</>;
|
||||
s += <span class="hl-Filter">{str.substr(i, filter.length)}</span>;
|
||||
start = i + filter.length;
|
||||
s += <span class="hl-Filter">{str.substr(i, length)}</span>;
|
||||
start = i + length;
|
||||
}
|
||||
return s + <>{str.substr(start)}</>;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user