Skip to content

Commit

Permalink
Tooltip regex matches gchq#279
Browse files Browse the repository at this point in the history
Tooltip shows offset and matched groups
  • Loading branch information
qistoph committed Oct 11, 2018
1 parent d6c6981 commit dce542a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/core/operations/RegularExpression.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ function regexList (input, regex, displayTotal, matches, captureGroups) {
*/
function regexHighlight (input, regex, displayTotal) {
let output = "",
title = "",
m,
hl = 1,
i = 0,
Expand All @@ -241,8 +242,16 @@ function regexHighlight (input, regex, displayTotal) {
// Add up to match
output += Utils.escapeHtml(input.slice(i, m.index));

title = "Offset: " + m.index + "
";
if (m.length > 1) {
title += "Groups:
";
for ( let n = 1; n < m.length; ++n) {
title += n + ": " + m[n] + "&#10;";
}
}

// 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
hl = hl === 1 ? 2 : 1;
Expand Down

0 comments on commit dce542a

Please sign in to comment.