@@ -202,7 +202,7 @@ document.addEventListener('DOMContentLoaded', () => {
202202 // Search functionality
203203 const clearSearchButton = document . getElementById ( 'clear-search' ) ;
204204 searchInput . addEventListener ( 'input' , ( e ) => {
205- const query = e . target . value . toLowerCase ( ) ;
205+ const query = e . target . value ;
206206 const activeSnippets = dbData . snippets . filter ( s => ! s . isDeleted ) ;
207207
208208 if ( query . trim ( ) === '' ) {
@@ -299,11 +299,11 @@ document.addEventListener('DOMContentLoaded', () => {
299299 function matchesQuery ( text , query ) {
300300 if ( ! query . trim ( ) ) return false ;
301301 try {
302- const regex = new RegExp ( query , 'i' ) ; // case-insensitive
302+ const regex = new RegExp ( query ) ; // case-sensitive
303303 return regex . test ( text ) ;
304304 } catch ( error ) {
305305 // If regex is invalid, fall back to literal string search
306- return text . toLowerCase ( ) . includes ( query . toLowerCase ( ) ) ;
306+ return text . includes ( query ) ;
307307 }
308308 }
309309
@@ -313,13 +313,27 @@ document.addEventListener('DOMContentLoaded', () => {
313313
314314 try {
315315 // Try to use the query as a regex pattern
316- const regex = new RegExp ( `(${ query } )` , 'gi' ) ;
317- return text . replace ( regex , '<mark class="search-highlight">$1</mark>' ) ;
316+ const regex = new RegExp ( `(${ query } )` , 'g' ) ; // case-sensitive, global
317+ let matchCount = 0 ;
318+ return text . replace ( regex , ( match , group1 ) => {
319+ matchCount ++ ;
320+ if ( matchCount <= 3 ) {
321+ return `<mark class="search-highlight">${ group1 } </mark>` ;
322+ }
323+ return group1 ; // Return without highlighting for matches beyond 3
324+ } ) ;
318325 } catch ( error ) {
319326 // If regex is invalid, escape special characters and search as literal string
320327 const escapedQuery = query . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' ) ;
321- const regex = new RegExp ( `(${ escapedQuery } )` , 'gi' ) ;
322- return text . replace ( regex , '<mark class="search-highlight">$1</mark>' ) ;
328+ const regex = new RegExp ( `(${ escapedQuery } )` , 'g' ) ;
329+ let matchCount = 0 ;
330+ return text . replace ( regex , ( match , group1 ) => {
331+ matchCount ++ ;
332+ if ( matchCount <= 3 ) {
333+ return `<mark class="search-highlight">${ group1 } </mark>` ;
334+ }
335+ return group1 ; // Return without highlighting for matches beyond 3
336+ } ) ;
323337 }
324338 }
325339
0 commit comments