Fixed a crash

This commit is contained in:
Simon Cambier
2022-05-02 18:36:33 +02:00
parent 228e410592
commit cb84f109c0
3 changed files with 1 additions and 5 deletions

View File

@@ -1,5 +1,4 @@
<script lang="ts"> <script lang="ts">
import type { Query } from "src/query";
import type { ResultNote } from "../globals" import type { ResultNote } from "../globals"
import { getMatches } from "../search" import { getMatches } from "../search"
import { highlighter, makeExcerpt, stringsToRegex } from "../utils" import { highlighter, makeExcerpt, stringsToRegex } from "../utils"

View File

@@ -31,10 +31,6 @@ export class Query {
return this.segments.map(({ value }) => value).join(' ') 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 the terms that are encased in quotes
* @returns * @returns

View File

@@ -57,6 +57,7 @@ export function getAllIndices(text: string, regex: RegExp): SearchMatch[] {
} }
export function stringsToRegex(strings: string[]): RegExp { export function stringsToRegex(strings: string[]): RegExp {
if (!strings.length) return /^$/
return new RegExp(strings.map(s => `(${escapeRegex(s)})`).join('|'), 'gi') return new RegExp(strings.map(s => `(${escapeRegex(s)})`).join('|'), 'gi')
} }