Skip to content

Commit

Permalink
Merge pull request #172 from PROCEED-Labs/ms2/fuzy-search
Browse files Browse the repository at this point in the history
Sort matches before highlighting text
  • Loading branch information
winniel24 authored Nov 24, 2023
2 parents a615382 + 80c8990 commit 3d00692
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/management-system-v2/lib/useFuzySearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ function highlightText<TObj>(

const result: JSX.Element[] = [];
let lastIndex = 0;
for (const [start, end] of matches.indices) {
const sortedMatches = matches.indices.toSorted((a, b) => a[0] - b[0]);

for (const [start, end] of sortedMatches) {
if (lastIndex < start)
result.push(<span key={lastIndex}>{value.slice(lastIndex, start)}</span>);

Expand Down

0 comments on commit 3d00692

Please sign in to comment.