Skip to content

Commit

Permalink
Sort matches before highlighting text
Browse files Browse the repository at this point in the history
  • Loading branch information
FelipeTrost committed Nov 23, 2023
1 parent 3429919 commit 80c8990
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 80c8990

Please sign in to comment.