@@ -7,6 +7,7 @@ document.addEventListener('DOMContentLoaded', () => {
77 const sidebar = document . getElementById ( 'sidebar' ) ;
88 const sidebarBackdrop = document . getElementById ( 'sidebar-backdrop' ) ;
99 const themeToggle = document . getElementById ( 'theme-toggle' ) ;
10+ const searchInfoBar = document . getElementById ( 'search-info-bar' ) ;
1011 let dbData = null ;
1112 let currentSnippets = [ ] ;
1213 let loadedCount = 0 ;
@@ -220,6 +221,9 @@ document.addEventListener('DOMContentLoaded', () => {
220221 highlightedValue : content . value // No highlighting
221222 } ) )
222223 } ) ) ;
224+
225+ // Hide search info bar when no search is active
226+ searchInfoBar . classList . add ( 'hidden' ) ;
223227 } else {
224228 // Filter snippets and determine which tab should be active
225229 const filteredSnippets = activeSnippets . filter ( snippet => {
@@ -265,6 +269,35 @@ document.addEventListener('DOMContentLoaded', () => {
265269 } ) ) ;
266270
267271 currentSnippets = filteredSnippets ;
272+
273+ // Show search info bar with match information
274+ const snippetCount = currentSnippets . length ;
275+ const totalSnippets = activeSnippets . length ;
276+
277+ // Count total matches across all snippets
278+ let totalMatches = 0 ;
279+ currentSnippets . forEach ( snippet => {
280+ // Count matches in name
281+ if ( matchesQuery ( snippet . name , query ) ) {
282+ totalMatches ++ ;
283+ }
284+ // Count matches in description
285+ if ( snippet . description && matchesQuery ( snippet . description , query ) ) {
286+ totalMatches ++ ;
287+ }
288+ // Count matches in content
289+ snippet . content . forEach ( content => {
290+ const highlighted = highlightSearchMatches ( content . value , query ) ;
291+ if ( highlighted !== content . value ) {
292+ // Count the number of <mark> tags (each represents a match)
293+ const matchCount = ( highlighted . match ( / < m a r k [ ^ > ] * > .* ?< \/ m a r k > / g) || [ ] ) . length ;
294+ totalMatches += matchCount ;
295+ }
296+ } ) ;
297+ } ) ;
298+
299+ searchInfoBar . innerHTML = `${ totalMatches } match${ totalMatches !== 1 ? 'es' : '' } found in ${ snippetCount } snippet${ snippetCount !== 1 ? 's' : '' } ` ;
300+ searchInfoBar . classList . remove ( 'hidden' ) ;
268301 }
269302
270303 loadedCount = 0 ;
0 commit comments