mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
1 parent
0fa2f07d64
commit
cd97869375
1 file changed
+4
-3
@@ -7,8 +7,8 @@ export class SearchStore {
|
|||||||
* An utility methods escaping user string to safely pass it into new Regex(variable)
|
* An utility methods escaping user string to safely pass it into new Regex(variable)
|
||||||
* @param value Unescaped string
|
* @param value Unescaped string
|
||||||
*/
|
*/
|
||||||
public static escapeRegex(value: string): string {
|
public static escapeRegex(value?: string): string {
|
||||||
return value.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
|
return value ? value.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&") : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,7 +70,8 @@ export class SearchStore {
|
|||||||
* @param query Search query from input
|
* @param query Search query from input
|
||||||
* @returns Array of line indexes [0, 0, 14, 17, 17, 17, 20...]
|
* @returns Array of line indexes [0, 0, 14, 17, 17, 17, 20...]
|
||||||
*/
|
*/
|
||||||
private findOccurrences(lines: string[] = [], query: string): number[] {
|
private findOccurrences(lines?: string[], query?: string): number[] {
|
||||||
|
lines ||= [];
|
||||||
const regex = new RegExp(SearchStore.escapeRegex(query), "gi");
|
const regex = new RegExp(SearchStore.escapeRegex(query), "gi");
|
||||||
|
|
||||||
return lines
|
return lines
|
||||||
|
|||||||
Reference in new issue
Block a user