Skip to content

Commit

Permalink
Merge pull request #9481 from hicommonwealth/kaleemNeslit.9279.search…
Browse files Browse the repository at this point in the history
…_break

fixed the crash issue on search bar in thread
  • Loading branch information
Kaleem Neslit authored Oct 24, 2024
2 parents ff1a9a8 + 09cb42b commit 07caf58
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ import { findAll } from 'highlight-words-core';
import React from 'react';
import smartTruncate from 'smart-truncate';

const escapeRegExp = (string: string) => {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // Escaping special characters
};

export const renderTruncatedHighlights = (
searchTerm: string,
docText: string,
) => {
// extract highlighted text
const words = searchTerm.split(/\s+/); // Split on whitespace
// Escape each word in the search term
const escapedWords = words.map((word) => escapeRegExp(word));
const chunks = findAll({
searchWords: [searchTerm.trim()],
searchWords: escapedWords,
textToHighlight: docText,
});

Expand Down

0 comments on commit 07caf58

Please sign in to comment.