mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-01-06 01:44:12 +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"],
|
["padding: 0 1em 0 0; vertical-align: top", "text-align: center"],
|
||||||
([h.class,
|
([h.class,
|
||||||
<span style={"text-align: center; line-height: 1em;" + h.value + style}>XXX</span>,
|
<span style={"text-align: center; line-height: 1em;" + h.value + style}>XXX</span>,
|
||||||
template.maybeXML(h.value.replace(/\s+/g, "\u00a0")
|
template.highlightRegexp(h.value, /\b[-\w]+(?=:)/g)]
|
||||||
.replace(/\b([-\w]+):/g, "<span class=\"hl-Filter\">$1:</span>"))]
|
|
||||||
for (h in highlight)
|
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);
|
commandline.echo(str, commandline.HL_NORMAL, commandline.FORCE_MULTILINE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,24 +76,51 @@ const template = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
highlightFilter: function (str, filter)
|
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")
|
if (typeof str == "xml")
|
||||||
return str;
|
return str;
|
||||||
if (str == "")
|
if (str == "")
|
||||||
return <>{str}</>;
|
return <>{str}</>;
|
||||||
|
|
||||||
let lcstr = String(str).toLowerCase();
|
XML.ignoreWhitespace = false;
|
||||||
let lcfilter = filter.toLowerCase();
|
|
||||||
str = String(str).replace(" ", "\u00a0");
|
str = String(str).replace(" ", "\u00a0");
|
||||||
let s = <></>;
|
let s = <></>;
|
||||||
let start = 0;
|
let start = 0;
|
||||||
let i;
|
for (let [i, length] in iter)
|
||||||
while ((i = lcstr.indexOf(lcfilter, start)) > -1)
|
|
||||||
{
|
{
|
||||||
XML.ignoreWhitespace = false;
|
|
||||||
s += <>{str.substring(start, i)}</>;
|
s += <>{str.substring(start, i)}</>;
|
||||||
s += <span class="hl-Filter">{str.substr(i, filter.length)}</span>;
|
s += <span class="hl-Filter">{str.substr(i, length)}</span>;
|
||||||
start = i + filter.length;
|
start = i + length;
|
||||||
}
|
}
|
||||||
return s + <>{str.substr(start)}</>;
|
return s + <>{str.substr(start)}</>;
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user