Tooltip regex matches #279

Tooltip shows offset and matched groups
This commit is contained in:
Chris van Marle 2018-10-11 14:15:51 +02:00 committed by d98762625
parent 8f7bb3a7c9
commit 9be674103f

View file

@ -227,6 +227,7 @@ function regexList (input, regex, displayTotal, matches, captureGroups) {
*/ */
function regexHighlight (input, regex, displayTotal) { function regexHighlight (input, regex, displayTotal) {
let output = "", let output = "",
title = "",
m, m,
hl = 1, hl = 1,
i = 0, i = 0,
@ -241,8 +242,16 @@ function regexHighlight (input, regex, displayTotal) {
// Add up to match // Add up to match
output += Utils.escapeHtml(input.slice(i, m.index)); output += Utils.escapeHtml(input.slice(i, m.index));
title = `Offset: ${m.index}\n`;
if (m.length > 1) {
title += "Groups:\n";
for (let n = 1; n < m.length; ++n) {
title += `\t${n}: ${m[n]}\n`;
}
}
// Add match with highlighting // Add match with highlighting
output += "<span class='hl"+hl+"'>" + Utils.escapeHtml(m[0]) + "</span>"; output += "<span class='hl"+hl+"' title='"+title+"'>" + Utils.escapeHtml(m[0]) + "</span>";
// Switch highlight // Switch highlight
hl = hl === 1 ? 2 : 1; hl = hl === 1 ? 2 : 1;