1+ import { UPPERCASE_PATTERN } from '@/api/const.ts' ;
12import { defineStore } from 'pinia' ;
23import { markRaw } from 'vue' ;
34
@@ -53,6 +54,7 @@ export const useSearchStore = defineStore('searchStore', {
5354 highlightAll (
5455 this . deltaEl ,
5556 this . searchQuery ,
57+ UPPERCASE_PATTERN . test ( this . searchQuery ) ,
5658 /*IN/OUT*/ this . foundEls
5759 ) ;
5860 this . currentIndex = - 1 ;
@@ -80,7 +82,6 @@ export const useSearchStore = defineStore('searchStore', {
8082
8183const CLASS_FOUND = 'jsdiff-found' ;
8284const CLASS_FOUND_THIS = 'jsdiff-found-this' ;
83- const UPPERCASE_PATTERN = / \p{ Lu} / u; // 'u' flag enables Unicode matching
8485
8586function indexInBound ( index : number , arrayLength : number ) : number {
8687 if ( index < 0 ) {
@@ -119,6 +120,7 @@ function highlightCurrent(el: HTMLElement) {
119120function highlightAll (
120121 container : HTMLElement | null ,
121122 query : string ,
123+ isCaseSensitive : boolean ,
122124 /*IN/OUT*/ els : HTMLElement [ ]
123125) {
124126 if ( ! container ) {
@@ -137,9 +139,9 @@ function highlightAll(
137139
138140 if ( isLeafNode ) {
139141 const text = firstChild . textContent || firstChild . innerText ;
140- const hasMatch = UPPERCASE_PATTERN . test ( query )
141- ? text . includes ( query ) // case-sensitive
142- : text . toLocaleLowerCase ( ) . includes ( query ) ; // case-insensitive
142+ const hasMatch = isCaseSensitive
143+ ? text . includes ( query )
144+ : text . toLocaleLowerCase ( ) . includes ( query ) ;
143145
144146 if ( ! hasMatch ) {
145147 return ;
@@ -160,7 +162,7 @@ function highlightAll(
160162 const child = containerNodes [ n ] ;
161163
162164 if ( child . nodeType === Node . ELEMENT_NODE ) {
163- highlightAll ( child , query , els ) ; // recursion
165+ highlightAll ( child , query , isCaseSensitive , els ) ; // recursion
164166 }
165167 }
166168 }
0 commit comments