41
41
const endLocationLine = $ ( e . target ) . data ( 'endLocationLine' ) ;
42
42
const editor = ace . edit ( "editor" ) ;
43
43
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 ) ;
46
48
// Decode the content (HTML encoded) for Ace to display
47
49
// 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
+ // }
58
60
editor . getSession ( ) . setValue ( content ) ;
59
61
editor . resize ( ) ;
60
62
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 ) ;
63
66
$ ( '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 ) ;
65
69
} ) ;
66
70
67
71
const templateInsertion = new TemplateInsertion ( data ) ;
@@ -175,7 +179,7 @@ class TemplateInsertion {
175
179
}
176
180
return fn . slice ( $this . mt . sourcePath . length ) ;
177
181
} ;
178
-
182
+ var matchCount = 1 ;
179
183
for ( let match of $this . md ) {
180
184
let excerpt = ( match . excerpt || '' ) || match . sample ;
181
185
if ( match . ruleId === ruleId || match . ruleName === ruleId ) {
@@ -190,6 +194,8 @@ class TemplateInsertion {
190
194
. data ( 'startLocationLine' , $l )
191
195
. data ( 'endLocationLine' , $e )
192
196
. text ( removePrefix ( match . fileName ) ) ;
197
+ $li . append ( matchCount ++ ) ;
198
+ $li . append ( ". " ) ;
193
199
$li . append ( $a ) ;
194
200
$ ( '#file_listing_modal ul' ) . append ( $li ) ;
195
201
0 commit comments