From 9be674103f64526d76b5bbddbdc681272786cd78 Mon Sep 17 00:00:00 2001 From: Chris van Marle Date: Thu, 11 Oct 2018 14:15:51 +0200 Subject: [PATCH] Tooltip regex matches #279 Tooltip shows offset and matched groups --- src/core/operations/RegularExpression.mjs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/core/operations/RegularExpression.mjs b/src/core/operations/RegularExpression.mjs index 152c276e..03918982 100644 --- a/src/core/operations/RegularExpression.mjs +++ b/src/core/operations/RegularExpression.mjs @@ -227,6 +227,7 @@ function regexList (input, regex, displayTotal, matches, captureGroups) { */ function regexHighlight (input, regex, displayTotal) { let output = "", + title = "", m, hl = 1, i = 0, @@ -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}\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 - output += "" + Utils.escapeHtml(m[0]) + ""; + output += "" + Utils.escapeHtml(m[0]) + ""; // Switch highlight hl = hl === 1 ? 2 : 1;