Skip to content

Commit

Permalink
fix use of the regexp in the resultshighlights
Browse files Browse the repository at this point in the history
  • Loading branch information
blackforestboi committed Jul 23, 2024
1 parent 0a54203 commit c9a6908
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/custom-lists/ui/CollectionPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,20 +237,18 @@ class SpacePicker extends StatefulUIElement<
// Function to highlight matching text
const highlightText = (text: string, query: string) => {
if (!query) return text
const segments = query.split('/')
const lastQuery = segments.length > 0 ? segments.pop() : query

const parts = text.split(new RegExp(`(${lastQuery})`, 'gi'))
return parts.map((part, index) =>
part.toLowerCase() === lastQuery.toLowerCase() &&
lastQuery.length > 0 ? (
<HighlightedTextSpan key={index}>
{part}
</HighlightedTextSpan>
) : (
part
),
)

const parts = text.split(query)
return parts.map((part, index) => (
<>
{part}
{index < parts.length - 1 && (
<HighlightedTextSpan key={index}>
{query}
</HighlightedTextSpan>
)}
</>
))
}

return baseEntries.map((baseEntry, index) => {
Expand Down

0 comments on commit c9a6908

Please sign in to comment.