Skip to content

Commit 4f7bda6

Browse files
committed
fix: positionOffset & contextLenght calculation
1 parent 1827bbc commit 4f7bda6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/requestHandler.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -997,8 +997,8 @@ export default class RequestHandler {
997997
errorCode: ErrorCode.InvalidSearch,
998998
});
999999
}
1000-
const contextLength: number =
1001-
parseInt(req.query.contextLength as string, 10) ?? 100;
1000+
const contextLengthRaw = parseInt(req.query.contextLength as string, 10);
1001+
const contextLength = Number.isNaN(contextLengthRaw) ? 100 : contextLengthRaw;
10021002
let search: ReturnType<typeof prepareSimpleSearch>;
10031003
try {
10041004
search = prepareSimpleSearch(query);
@@ -1019,9 +1019,9 @@ export default class RequestHandler {
10191019

10201020
// We added the headline to the search text with 2 line breaks.
10211021
// That causes the start and end position numbers to be wrong with an offset
1022-
// of the char length of the headline + 2 line breaks.
1022+
// of the char length of the headline line breaks.
10231023
// This is fixed by substracting the positionOffset from the start and end position.
1024-
const positionOffset = filenamePrefix.length - 1;
1024+
const positionOffset = filenamePrefix.length;
10251025

10261026
if (result) {
10271027
const contextMatches: SearchContext[] = [];

0 commit comments

Comments
 (0)