commit c4af40e64f3f33c84ce3b25bf813e8061b060efc
parent afc42d195231016b4abaa2576a8fdb9200db23fc
Author: William Casarin <jb55@jb55.com>
Date: Tue, 5 Dec 2023 12:33:16 -0800
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.
Diffstat:
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git 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<NoteKey>()
-
+
+ // 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: {