aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md3
-rw-r--r--include/SearchBar.hpp3
-rw-r--r--src/QuickMedia.cpp20
-rw-r--r--src/SearchBar.cpp10
4 files changed, 32 insertions, 4 deletions
diff --git a/README.md b/README.md
index 625938d..53e1cc2 100644
--- a/README.md
+++ b/README.md
@@ -77,4 +77,5 @@ Add support for special formatting for posts by admins on imageboards.\
For image boards, track (You)'s and show notification when somebody replies to your post.\
In image boards when viewing videos, automatically play the next one after the current one has finished playing (just like the youtube plugin does).\
When viewing images the image download start from page 1 to the end page. The image download should start from the viewing page.\
-Go to next chapter when reaching the end of the chapter in image endless mode.\ \ No newline at end of file
+Go to next chapter when reaching the end of the chapter in image endless mode.\
+Some text is not visible on 4chan, such as code blocks. \ No newline at end of file
diff --git a/include/SearchBar.hpp b/include/SearchBar.hpp
index e986368..7a6c483 100644
--- a/include/SearchBar.hpp
+++ b/include/SearchBar.hpp
@@ -12,6 +12,8 @@ namespace QuickMedia {
// Return true to consume the search (clear the search field)
using TextSubmitCallback = std::function<bool(const sf::String &text)>;
+ using TextBeginTypingCallback = std::function<void()>;
+
class SearchBar {
public:
SearchBar(sf::Font &font, sf::Texture &plugin_logo);
@@ -28,6 +30,7 @@ namespace QuickMedia {
TextUpdateCallback onTextUpdateCallback;
TextSubmitCallback onTextSubmitCallback;
+ TextBeginTypingCallback onTextBeginTypingCallback;
int text_autosearch_delay;
private:
sf::Text text;
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 15e345b..55f8688 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -211,6 +211,7 @@ namespace QuickMedia {
case Page::SEARCH_SUGGESTION:
body->draw_thumbnails = current_plugin->search_suggestions_has_thumbnails();
search_suggestion_page();
+ search_bar->onTextBeginTypingCallback = nullptr;
break;
#if 0
case Page::SEARCH_RESULT:
@@ -231,6 +232,8 @@ namespace QuickMedia {
window.setKeyRepeatEnabled(false);
window.setFramerateLimit(4);
image_page();
+ body->filter_search_fuzzy("");
+ body->select_first_item();
window.setFramerateLimit(0);
window.setKeyRepeatEnabled(true);
break;
@@ -238,6 +241,8 @@ namespace QuickMedia {
case Page::IMAGES_CONTINUOUS: {
body->draw_thumbnails = false;
image_continuous_page();
+ body->filter_search_fuzzy("");
+ body->select_first_item();
break;
}
case Page::CONTENT_LIST: {
@@ -333,6 +338,7 @@ namespace QuickMedia {
void Program::search_suggestion_page() {
std::string update_search_text;
bool search_running = false;
+ bool typing = false;
Body history_body(this, font, bold_font);
const float tab_text_size = 18.0f;
@@ -386,16 +392,24 @@ namespace QuickMedia {
});
}
- search_bar->onTextUpdateCallback = [&update_search_text, this, &tabs, &selected_tab](const std::string &text) {
+ search_bar->onTextBeginTypingCallback = [&typing]() {
+ typing = true;
+ };
+
+ search_bar->onTextUpdateCallback = [&update_search_text, this, &tabs, &selected_tab, &typing](const std::string &text) {
if(tabs[selected_tab].body == body && !current_plugin->search_is_filter())
update_search_text = text;
else {
tabs[selected_tab].body->filter_search_fuzzy(text);
tabs[selected_tab].body->clamp_selection();
}
+ typing = false;
};
- search_bar->onTextSubmitCallback = [this, &tabs, &selected_tab](const std::string &text) -> bool {
+ search_bar->onTextSubmitCallback = [this, &tabs, &selected_tab, &typing](const std::string &text) -> bool {
+ if(typing || text.empty())
+ return false;
+
Page next_page = current_plugin->get_page_after_search();
// TODO: This shouldn't be done if search_selected_suggestion fails
if(search_selected_suggestion(tabs[selected_tab].body, body, current_plugin, content_title, content_url) != SearchResult::OK) {
@@ -552,6 +566,8 @@ namespace QuickMedia {
search_bar->draw(window, false);
window.display();
}
+
+ search_bar->onTextBeginTypingCallback = nullptr;
}
void Program::search_result_page() {
diff --git a/src/SearchBar.cpp b/src/SearchBar.cpp
index 2008447..f9b6d0e 100644
--- a/src/SearchBar.cpp
+++ b/src/SearchBar.cpp
@@ -14,6 +14,7 @@ namespace QuickMedia {
SearchBar::SearchBar(sf::Font &font, sf::Texture &plugin_logo) :
onTextUpdateCallback(nullptr),
onTextSubmitCallback(nullptr),
+ onTextBeginTypingCallback(nullptr),
text_autosearch_delay(0),
text("Search...", font, 18),
show_placeholder(true),
@@ -105,13 +106,15 @@ namespace QuickMedia {
text.setString("Search...");
text.setFillColor(text_placeholder_color);
}
+ if(!updated_search && onTextBeginTypingCallback)
+ onTextBeginTypingCallback();
updated_search = true;
time_since_search_update.restart();
}
} else if(codepoint == 13) { // Return
bool clear_search = true;
if(onTextSubmitCallback)
- clear_search = onTextSubmitCallback(text.getString());
+ clear_search = onTextSubmitCallback(show_placeholder ? "" : text.getString());
if(clear_search)
clear();
@@ -124,6 +127,8 @@ namespace QuickMedia {
sf::String str = text.getString();
str += codepoint;
text.setString(str);
+ if(!updated_search && onTextBeginTypingCallback)
+ onTextBeginTypingCallback();
updated_search = true;
time_since_search_update.restart();
} else if(codepoint == '\n')
@@ -137,6 +142,7 @@ namespace QuickMedia {
text.setString("Search...");
text.setFillColor(text_placeholder_color);
needs_update = true;
+ updated_search = false;
}
void SearchBar::append_text(const std::string &text_to_add) {
@@ -148,6 +154,8 @@ namespace QuickMedia {
sf::String str = text.getString();
str += text_to_add;
text.setString(str);
+ if(!updated_search && onTextBeginTypingCallback)
+ onTextBeginTypingCallback();
updated_search = true;
time_since_search_update.restart();
needs_update = true;