Skip to content

Commit 13a748c

Browse files
authored
Transcript search fix (#2014)
* Fixed transcript search bugs * Prettify
1 parent 56c7b72 commit 13a748c

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

components/hearing/Transcriptions.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,17 @@ const TranscriptItem = forwardRef(function TranscriptItem(
289289
}
290290
const highlightText = (text: string, term: string) => {
291291
if (!term) return text
292-
const regex = new RegExp(`(${term})`, "gi")
293-
return text
294-
.split(regex)
295-
.map((part, i) => (regex.test(part) ? <mark key={i}>{part}</mark> : part))
292+
const escaped = term.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
293+
const regex = new RegExp(`(${escaped})`, "gi")
294+
return text.split(regex).map((part, i) =>
295+
regex.test(part) ? (
296+
<mark key={i} className={`p-0`}>
297+
{part}
298+
</mark>
299+
) : (
300+
part
301+
)
302+
)
296303
}
297304

298305
return (

0 commit comments

Comments
 (0)