Skip to content

Commit 112d2e1

Browse files
author
faux
committed
fix type warnings. switch from matchAll to match
1 parent 662b694 commit 112d2e1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

plugs/index/snippet_extractor.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff 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);

0 commit comments

Comments
 (0)