From c4af40e64f3f33c84ce3b25bf813e8061b060efc Mon Sep 17 00:00:00 2001 From: William Casarin Date: Tue, 5 Dec 2023 12:33:16 -0800 Subject: [PATCH] textsearch: don't clear results if we get no results while typing When you are searching for results, don't wipe the current result set if there are some previous results and the current query is returning 0 results. This is pretty common when you start typing, it's weird for the results to randomly clear when looking for stuff. --- damus/Views/Search/PullDownSearch.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/damus/Views/Search/PullDownSearch.swift b/damus/Views/Search/PullDownSearch.swift index 2228ebde..fc1c75a6 100644 --- a/damus/Views/Search/PullDownSearch.swift +++ b/damus/Views/Search/PullDownSearch.swift @@ -18,11 +18,18 @@ struct PullDownSearchView: View { let on_cancel: () -> Void func do_search(query: String) { - let note_keys = state.ndb.text_search(query: query, limit: 16) + let limit = 16 + var note_keys = state.ndb.text_search(query: query, limit: limit, order: .newest_first) var res = [NostrEvent]() // TODO: fix duplicate results from search var keyset = Set() - + + // try reverse because newest first is a bit buggy on partial searches + if note_keys.count == 0 { + // don't touch existing results if there are no new ones + return + } + do { let txn = NdbTxn(ndb: state.ndb) for note_key in note_keys { @@ -64,6 +71,7 @@ struct PullDownSearchView: View { if is_active { Button(action: { search_text = "" + results = [] end_editing() on_cancel() }, label: {