File tree Expand file tree Collapse file tree 1 file changed +3
-2
lines changed
Expand file tree Collapse file tree 1 file changed +3
-2
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ export function extractSnippetAroundIndex(
1111
1212 // Find which line contains the index
1313 const textBeforeIndex = text . slice ( 0 , index ) ;
14- let linesBeforeIndex = textBeforeIndex . matchAll ( new RegExp ( "/\n/" , "g" ) ) . toArray ( ) ;
14+ const linesBeforeIndex = textBeforeIndex . matchAll ( new RegExp ( "/\n/" , "g" ) ) . toArray ( ) ;
1515 targetLineIndex = linesBeforeIndex . length ;
1616
1717 if ( targetLineIndex === - 1 ) {
@@ -31,7 +31,8 @@ export function extractSnippetAroundIndex(
3131 // If snippet is still too long, truncate while centering around the reference
3232 if ( snippet . length > maxSnippetLength ) {
3333 // Get the position of the index within the snippet based on the index of the newline character at the end of the preceding line
34- const indexInSnippet = index - linesBeforeIndex . pop ( ) . index - 1 ;
34+ const previousNewline = linesBeforeIndex . pop ( ) ;
35+ const indexInSnippet = index - 1 - ( previousNewline ? previousNewline . index : 0 ) ;
3536
3637 // Center the truncation around the reference
3738 const halfLength = Math . floor ( maxSnippetLength / 2 ) ;
You can’t perform that action at this time.
0 commit comments