From dce542a8a916a2d05d8d05b11ec9f247344cfb52 Mon Sep 17 00:00:00 2001 From: Chris van Marle Date: Thu, 11 Oct 2018 14:15:51 +0200 Subject: [PATCH 1/3] 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 152c276ece..c014394d09 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 + " "; + if (m.length > 1) { + title += "Groups: "; + for ( let n = 1; n < m.length; ++n) { + title += n + ": " + m[n] + " "; + } + } + // Add match with highlighting - output += "" + Utils.escapeHtml(m[0]) + ""; + output += "" + Utils.escapeHtml(m[0]) + ""; // Switch highlight hl = hl === 1 ? 2 : 1; From e086952d09c1d8450d1aefe094179a2eae0c5a4c Mon Sep 17 00:00:00 2001 From: Chris van Marle Date: Thu, 11 Oct 2018 15:52:58 +0200 Subject: [PATCH 2/3] Fix lint errors --- src/core/operations/RegularExpression.mjs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/core/operations/RegularExpression.mjs b/src/core/operations/RegularExpression.mjs index c014394d09..92004ed231 100644 --- a/src/core/operations/RegularExpression.mjs +++ b/src/core/operations/RegularExpression.mjs @@ -227,7 +227,7 @@ function regexList (input, regex, displayTotal, matches, captureGroups) { */ function regexHighlight (input, regex, displayTotal) { let output = "", - title = "", + title = "", m, hl = 1, i = 0, @@ -242,13 +242,13 @@ 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] + " "; - } - } + title = "Offset: " + m.index + " "; + if (m.length > 1) { + title += "Groups: "; + for (let n = 1; n < m.length; ++n) { + title += n + ": " + m[n] + " "; + } + } // Add match with highlighting output += "" + Utils.escapeHtml(m[0]) + ""; From 88f7e63c5606eeb24f1a442f97f6a8840ddf163e Mon Sep 17 00:00:00 2001 From: Chris van Marle Date: Fri, 12 Oct 2018 15:49:43 +0200 Subject: [PATCH 3/3] Use template strings and \n as suggested in review --- src/core/operations/RegularExpression.mjs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/operations/RegularExpression.mjs b/src/core/operations/RegularExpression.mjs index 92004ed231..b0c638d495 100644 --- a/src/core/operations/RegularExpression.mjs +++ b/src/core/operations/RegularExpression.mjs @@ -242,11 +242,11 @@ function regexHighlight (input, regex, displayTotal) { // Add up to match output += Utils.escapeHtml(input.slice(i, m.index)); - title = "Offset: " + m.index + " "; + title = `Offset: ${m.index}\n`; if (m.length > 1) { - title += "Groups: "; + title += "Groups:\n"; for (let n = 1; n < m.length; ++n) { - title += n + ": " + m[n] + " "; + title += `${n}: ${m[n]}\n`; } }