1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-03-09 14:41:17 -05:00
parent 0fa2f07d64
commit cd97869375

View File

@ -7,8 +7,8 @@ export class SearchStore {
* An utility methods escaping user string to safely pass it into new Regex(variable)
* @param value Unescaped string
*/
public static escapeRegex(value: string): string {
return value.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
public static escapeRegex(value?: string): string {
return value ? value.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&") : "";
}
/**
@ -70,7 +70,8 @@ export class SearchStore {
* @param query Search query from input
* @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");
return lines