@@ -6,12 +6,12 @@ import { ChangeEvent, KeyboardEvent, useEffect, useRef, useState } from 'react';
66import { FaUser } from 'react-icons/fa' ;
77import { FiSearch } from 'react-icons/fi' ;
88import { MdBusiness } from 'react-icons/md' ;
9- import regexifyString from 'regexify-string' ;
109
1110import API from '../../api' ;
1211import useOutsideClick from '../../hooks/useOutsideClick' ;
1312import { ErrorKind , Repository , SearchQuery } from '../../types' ;
1413import alertDispatcher from '../../utils/alertDispatcher' ;
14+ import regexifyString from '../../utils/regexifyString' ;
1515import Loading from './Loading' ;
1616import RepositoryIcon from './RepositoryIcon' ;
1717import styles from './SearchRepositories.module.css' ;
@@ -162,6 +162,21 @@ const SearchRepositories = (props: Props) => {
162162 }
163163 } ;
164164
165+ // Highlights the typed search term in repository names.
166+ const getHighlightedRepositoryName = ( repositoryName : string ) => {
167+ return regexifyString ( {
168+ pattern : new RegExp ( escapeRegExp ( searchName ) , 'gi' ) ,
169+ decorator : ( match : string , index : number ) => {
170+ return (
171+ < span key = { `match_${ repositoryName } _${ index } ` } className = "fw-bold highlighted" >
172+ { match }
173+ </ span >
174+ ) ;
175+ } ,
176+ input : repositoryName ,
177+ } ) ;
178+ } ;
179+
165180 const cleanTimeout = ( ) => {
166181 if ( ! isNull ( dropdownTimeout ) ) {
167182 clearTimeout ( dropdownTimeout ) ;
@@ -298,23 +313,7 @@ const SearchRepositories = (props: Props) => {
298313 < td className = "align-middle" >
299314 < div className = { styles . truncateWrapper } >
300315 < div className = "text-truncate" >
301- { searchName === '' ? (
302- < > { item . name } </ >
303- ) : (
304- < >
305- { regexifyString ( {
306- pattern : new RegExp ( escapeRegExp ( searchName ) , 'gi' ) ,
307- decorator : ( match : string , index : number ) => {
308- return (
309- < span key = { `match_${ item . name } _${ index } ` } className = "fw-bold highlighted" >
310- { match }
311- </ span >
312- ) ;
313- } ,
314- input : item . name ,
315- } ) }
316- </ >
317- ) }
316+ { searchName === '' ? < > { item . name } </ > : < > { getHighlightedRepositoryName ( item . name ) } </ > }
318317 </ div >
319318 </ div >
320319 </ td >
0 commit comments