Skip to content

Commit b27e533

Browse files
committed
Only use the highlighting renderer for the current page and its neighbors
1 parent 2be5dee commit b27e533

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/components/pdf-viewer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ function highlightSearch(text: string, query: string): string {
7474
let regex = regexCache.get(query);
7575
// Check if the regex for this query is cached
7676
if (!regex) {
77-
console.debug("Cache miss, compiling regex for highlighting query:", query);
7877
// Split and escape the query segments
7978
const escapedSegments = query
8079
.split(/(?:[\r\n]|\s{2,})+/)
8180
.filter(Boolean) // Remove empty segments
81+
.map(s => s.trim())
8282
.map(escapeRegExp);
8383

8484
if (escapedSegments.length === 0) return text;
@@ -472,7 +472,7 @@ const PdfViewer = ({
472472
className="mb-4"
473473
>
474474
<Page
475-
customTextRenderer={textRenderer}
475+
customTextRenderer={[currentPage - 1, currentPage, currentPage + 1].includes(index + 1) ? textRenderer : undefined}
476476
pageNumber={index + 1}
477477
scale={scale}
478478
rotate={rotation}

0 commit comments

Comments
 (0)