Skip to content

Commit d99da6a

Browse files
authored
Ignore case while pattern-matching to highlight search results (#3326)
1 parent 72cd0e5 commit d99da6a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

.changeset/slimy-cows-press.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook": patch
3+
---
4+
5+
Ignore case while highlighting search results.

packages/gitbook/src/components/Search/SearchSectionResultItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ export const SearchSectionResultItem = React.forwardRef(function SearchSectionRe
8888
});
8989

9090
function highlightQueryInBody(body: string, query: string) {
91-
const idx = body.indexOf(query);
91+
const idx = body.toLocaleLowerCase().indexOf(query.toLocaleLowerCase());
9292

9393
// Ensure the query to be highlighted is visible in the body.
9494
return (
9595
<p className={tcls('text-sm', 'line-clamp-3', 'relative')}>
96-
<HighlightQuery query={query} text={idx < 20 ? body : `...${body.slice(idx - 15)}`} />
96+
<HighlightQuery query={query} text={idx < 20 ? body : `...${body.slice(idx - 10)}`} />
9797
</p>
9898
);
9999
}

0 commit comments

Comments
 (0)