From dd6182aef3463d27cb0c034241ca8167cd0921fa Mon Sep 17 00:00:00 2001 From: tophf Date: Mon, 28 Aug 2017 15:07:30 +0300 Subject: [PATCH] lint issues list: show rule name only on hover --- edit/lint.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/edit/lint.js b/edit/lint.js index c3dbf56c..8c7b1ad7 100644 --- a/edit/lint.js +++ b/edit/lint.js @@ -188,18 +188,18 @@ function updateLintReport(cm, delay) { const info = mark.__annotation; const isActiveLine = info.from.line === cm.getCursor().line; const pos = isActiveLine ? 'cursor' : (info.from.line + ',' + info.from.ch); - // stylelint rule added in parentheses at the end; extract it out for the stylelint info popup - const lintRuleName = info.message - .substring(info.message.lastIndexOf('('), info.message.length) - .replace(/[()]/g, ''); - const title = escapeHtml(info.message); - const message = title.length > 100 ? title.substr(0, 100) + '...' : title; + // rule name added in parentheses at the end; extract it out for the info popup + const text = info.message; + const parenPos = text.endsWith(')') ? text.lastIndexOf('(') : text.length; + const ruleName = text.slice(parenPos + 1, -1); + const title = escapeHtml(text); + const message = escapeHtml(text.substr(0, Math.min(100, parenPos)), {limit: 100}); if (isActiveLine || oldMarkers[pos] === message) { delete oldMarkers[pos]; } newMarkers[pos] = message; return ` - +
${info.severity}
${info.from.line + 1} @@ -226,9 +226,14 @@ function updateLintReport(cm, delay) { } } } - function escapeHtml(html) { + function escapeHtml(html, {limit} = {}) { const chars = {'&': '&', '<': '<', '>': '>', '"': '"', "'": ''', '/': '/'}; - return html.replace(/[&<>"'/]/g, char => chars[char]); + let ellipsis = ''; + if (limit && html.length > limit) { + html = html.substr(0, limit); + ellipsis = '...'; + } + return html.replace(/[&<>"'/]/g, char => chars[char]) + ellipsis; } }