From 6a82b66921c24d5310479df33abcf977ab231772 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 27 Sep 2020 04:19:57 +0200 Subject: Nyaa.si: search even if input string is empty This fixes being able to show all items when removing the search input. --- src/QuickMedia.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src') 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 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 { -- cgit v1.2.3