1
+ import { UPPERCASE_PATTERN } from '@/api/const.ts' ;
1
2
import { defineStore } from 'pinia' ;
2
3
import { markRaw } from 'vue' ;
3
4
@@ -53,6 +54,7 @@ export const useSearchStore = defineStore('searchStore', {
53
54
highlightAll (
54
55
this . deltaEl ,
55
56
this . searchQuery ,
57
+ UPPERCASE_PATTERN . test ( this . searchQuery ) ,
56
58
/*IN/OUT*/ this . foundEls
57
59
) ;
58
60
this . currentIndex = - 1 ;
@@ -80,7 +82,6 @@ export const useSearchStore = defineStore('searchStore', {
80
82
81
83
const CLASS_FOUND = 'jsdiff-found' ;
82
84
const CLASS_FOUND_THIS = 'jsdiff-found-this' ;
83
- const UPPERCASE_PATTERN = / \p{ Lu} / u; // 'u' flag enables Unicode matching
84
85
85
86
function indexInBound ( index : number , arrayLength : number ) : number {
86
87
if ( index < 0 ) {
@@ -119,6 +120,7 @@ function highlightCurrent(el: HTMLElement) {
119
120
function highlightAll (
120
121
container : HTMLElement | null ,
121
122
query : string ,
123
+ isCaseSensitive : boolean ,
122
124
/*IN/OUT*/ els : HTMLElement [ ]
123
125
) {
124
126
if ( ! container ) {
@@ -137,9 +139,9 @@ function highlightAll(
137
139
138
140
if ( isLeafNode ) {
139
141
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 ) ;
143
145
144
146
if ( ! hasMatch ) {
145
147
return ;
@@ -160,7 +162,7 @@ function highlightAll(
160
162
const child = containerNodes [ n ] ;
161
163
162
164
if ( child . nodeType === Node . ELEMENT_NODE ) {
163
- highlightAll ( child , query , els ) ; // recursion
165
+ highlightAll ( child , query , isCaseSensitive , els ) ; // recursion
164
166
}
165
167
}
166
168
}
0 commit comments