From 5e7c2f7e5ff92529dd4d8ecd021495b824760cb5 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Thu, 10 Nov 2022 21:19:10 +0100 Subject: [PATCH] Fixed a glitch that displayed the previous results when the query field was empty --- src/search/query.ts | 4 ++++ src/search/search-engine.ts | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/search/query.ts b/src/search/query.ts index d632464..bbe595c 100644 --- a/src/search/query.ts +++ b/src/search/query.ts @@ -36,6 +36,10 @@ export class Query { }, []) } + public isEmpty(): boolean { + return this.segments.length === 0 + } + public segmentsToStr(): string { return this.segments.map(({ value }) => value).join(' ') } diff --git a/src/search/search-engine.ts b/src/search/search-engine.ts index 88c6d31..3f77b78 100644 --- a/src/search/search-engine.ts +++ b/src/search/search-engine.ts @@ -190,6 +190,10 @@ export class SearchEngine { query: Query, options?: Partial<{ singleFilePath: string | null }> ): Promise { + if (query.isEmpty()) { + previousResults = [] + return [] + } // Get the raw results let results: SearchResult[] if (settings.simpleSearch) {