diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-09-27 04:19:57 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-09-27 04:22:31 +0200 |
commit | 6a82b66921c24d5310479df33abcf977ab231772 (patch) | |
tree | 47993e46978ee55f67157ee65068ca486a024e3b /src | |
parent | ca8171d80ceccf1538f2fef9ab2c96dc7192f9d1 (diff) |
Nyaa.si: search even if input string is empty
This fixes being able to show all items when removing the search input.
Diffstat (limited to 'src')
-rw-r--r-- | src/QuickMedia.cpp | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 05b65ea..cec7531 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -955,6 +955,7 @@ namespace QuickMedia { void Program::search_suggestion_page() { std::string update_search_text; + bool search_text_updated = false; bool search_running = false; bool typing = false; bool is_fourchan = current_plugin->name == "4chan"; @@ -1035,10 +1036,11 @@ namespace QuickMedia { std::string recommended_filter; - search_bar->onTextUpdateCallback = [&update_search_text, this, &tabs, &selected_tab, &typing, &recommended_body, &recommended_filter](const std::string &text) { - if(tabs[selected_tab].body == body && !current_plugin->search_is_filter()) + search_bar->onTextUpdateCallback = [&update_search_text, &search_text_updated, this, &tabs, &selected_tab, &typing, &recommended_body, &recommended_filter](const std::string &text) { + if(tabs[selected_tab].body == body && !current_plugin->search_is_filter()) { update_search_text = text; - else { + search_text_updated = true; + } else { tabs[selected_tab].body->filter_search_fuzzy(text); tabs[selected_tab].body->select_first_item(); } @@ -1147,7 +1149,7 @@ namespace QuickMedia { if(tabs[selected_tab].body) search_bar->update(); - if(!update_search_text.empty() && !search_running) { + if(search_text_updated && !search_running) { search_suggestion_future = std::async(std::launch::async, [this, update_search_text]() { BodyItems result; if(current_plugin->update_search_suggestions(update_search_text, result) != SuggestionResult::OK) { @@ -1156,11 +1158,12 @@ namespace QuickMedia { return result; }); update_search_text.clear(); + search_text_updated = false; search_running = true; } if(search_running && search_suggestion_future.valid() && search_suggestion_future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) { - if(update_search_text.empty()) { + if(!search_text_updated) { body->items = search_suggestion_future.get(); body->clamp_selection(); } else { @@ -2383,6 +2386,7 @@ namespace QuickMedia { void Program::content_list_page() { std::string update_search_text; + bool search_text_updated = false; bool search_running = false; std::future<BodyItems> search_future; @@ -2397,12 +2401,13 @@ namespace QuickMedia { return; } - search_bar->onTextUpdateCallback = [this, &update_search_text](const std::string &text) { + search_bar->onTextUpdateCallback = [this, &update_search_text, &search_text_updated](const std::string &text) { if(current_plugin->content_list_search_is_filter()) { body->filter_search_fuzzy(text); body->select_first_item(); } else { update_search_text = text; + search_text_updated = true; } }; @@ -2439,7 +2444,7 @@ namespace QuickMedia { search_bar->update(); - if(!update_search_text.empty() && !search_running) { + if(search_text_updated && !search_running) { search_future = std::async(std::launch::async, [this, update_search_text]() { BodyItems result; if(current_plugin->content_list_search(content_list_url, update_search_text, result) != SearchResult::OK) { @@ -2448,11 +2453,12 @@ namespace QuickMedia { return result; }); update_search_text.clear(); + search_text_updated = false; search_running = true; } if(search_running && search_future.valid() && search_future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) { - if(update_search_text.empty()) { + if(!search_text_updated) { body->items = search_future.get(); body->select_first_item(); } else { |