Fixed a crash
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
<script lang="ts">
|
||||
import type { Query } from "src/query";
|
||||
import type { ResultNote } from "../globals"
|
||||
import { getMatches } from "../search"
|
||||
import { highlighter, makeExcerpt, stringsToRegex } from "../utils"
|
||||
|
||||
@@ -31,10 +31,6 @@ export class Query {
|
||||
return this.segments.map(({ value }) => value).join(' ')
|
||||
}
|
||||
|
||||
public segmentsToRegex(): RegExp {
|
||||
return stringsToRegex(this.segments.map(s => s.value))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the terms that are encased in quotes
|
||||
* @returns
|
||||
|
||||
@@ -57,6 +57,7 @@ export function getAllIndices(text: string, regex: RegExp): SearchMatch[] {
|
||||
}
|
||||
|
||||
export function stringsToRegex(strings: string[]): RegExp {
|
||||
if (!strings.length) return /^$/
|
||||
return new RegExp(strings.map(s => `(${escapeRegex(s)})`).join('|'), 'gi')
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user