Skip to content

Commit f13cc8a

Browse files
authored
Adds numbering to issue results (#558)
1 parent 1952127 commit f13cc8a

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

AppInspector.CLI/html/resources/js/appinspector.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,31 @@
4141
const endLocationLine = $(e.target).data('endLocationLine');
4242
const editor = ace.edit("editor");
4343

44-
editor.setOption('firstLineNumber', startLocationLine - 3);
45-
44+
// Assume that the default context of 3 is used, the minimum line number is 1
45+
// TODO: Better handle context that isn't 3 length
46+
const actualStartNumber = Math.max(1, startLocationLine - 3);
47+
editor.setOption('firstLineNumber', actualStartNumber);
4648
// Decode the content (HTML encoded) for Ace to display
4749
// Disabled, needs better testing, since it's prone to XSS if content contains JS.
48-
// Maybe there is a better way of doing this.
49-
if (false) {
50-
const htmlEntityDecoder = (content) => {
51-
const textArea = document.createElement('textarea');
52-
textArea.innerHTML = content;
53-
return textArea.value;
54-
}
55-
content = htmlEntityDecoder(content);
56-
}
57-
50+
// TODO: Can this be rewritten to properly escape in a more limited fashion and use something like a <pre> tag?
51+
52+
// if (false) {
53+
// const htmlEntityDecoder = (content) => {
54+
// const textArea = document.createElement('textarea');
55+
// textArea.innerHTML = content;
56+
// return textArea.value;
57+
// }
58+
// content = htmlEntityDecoder(content);
59+
// }
5860
editor.getSession().setValue(content);
5961
editor.resize();
6062
editor.scrollToLine(0);
61-
editor.gotoLine(endLocationLine - startLocationLine + 1 + 3);
62-
63+
// We need to calculate the number relative to the number of lines in the content available
64+
// This assumes the first line is 1, even though we have explicitly numbered the lines otherwise
65+
editor.gotoLine(startLocationLine - actualStartNumber + 1);
6366
$('editor-container').removeClass('d-none');
64-
$('#match-line-number').text('Line number: ' + startLocationLine.toString());
67+
const locationString = startLocationLine < endLocationLine ? (startLocationLine.toString() + " - " + endLocationLine.toString()) : startLocationLine.toString();
68+
$('#match-line-number').text('Line number: ' + locationString);
6569
});
6670

6771
const templateInsertion = new TemplateInsertion(data);
@@ -175,7 +179,7 @@ class TemplateInsertion {
175179
}
176180
return fn.slice($this.mt.sourcePath.length);
177181
};
178-
182+
var matchCount = 1;
179183
for (let match of $this.md) {
180184
let excerpt = (match.excerpt || '') || match.sample;
181185
if (match.ruleId === ruleId || match.ruleName === ruleId) {
@@ -190,6 +194,8 @@ class TemplateInsertion {
190194
.data('startLocationLine', $l)
191195
.data('endLocationLine', $e)
192196
.text(removePrefix(match.fileName));
197+
$li.append(matchCount++);
198+
$li.append(". ");
193199
$li.append($a);
194200
$('#file_listing_modal ul').append($li);
195201

0 commit comments

Comments
 (0)