aboutsummaryrefslogtreecommitdiff
path: root/src/SearchBar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/SearchBar.cpp')
-rw-r--r--src/SearchBar.cpp31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/SearchBar.cpp b/src/SearchBar.cpp
index a621d02..63fbfc8 100644
--- a/src/SearchBar.cpp
+++ b/src/SearchBar.cpp
@@ -1,5 +1,7 @@
#include "../include/SearchBar.hpp"
#include "../include/Scale.hpp"
+#include <SFML/Window/Event.hpp>
+#include <SFML/Window/Clipboard.hpp>
#include <cmath>
#include <assert.h>
@@ -56,6 +58,12 @@ namespace QuickMedia {
window.draw(plugin_logo_sprite);
}
+ void SearchBar::on_event(sf::Event &event) {
+ if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::V && event.key.control) {
+ append_text(sf::Clipboard::getString());
+ }
+ }
+
void SearchBar::update() {
sf::Int32 elapsed_time = time_since_search_update.getElapsedTime().asMilliseconds();
if(updated_search && elapsed_time >= text_autosearch_delay) {
@@ -137,20 +145,7 @@ namespace QuickMedia {
if(clear_search)
clear();
} else if(codepoint > 31) { // Non-control character
- if(show_placeholder) {
- show_placeholder = false;
- text.setString("");
- text.setFillColor(sf::Color::White);
- }
- sf::String str = text.getString();
- str += codepoint;
- text.setString(str);
- clear_autocomplete_if_last_char_not_substr();
- if(!updated_search && onTextBeginTypingCallback)
- onTextBeginTypingCallback();
- updated_search = true;
- updated_autocomplete = true;
- time_since_search_update.restart();
+ append_text(sf::String(codepoint));
} else if(codepoint == '\n')
needs_update = true;
}
@@ -168,21 +163,27 @@ namespace QuickMedia {
}
void SearchBar::append_text(const std::string &text_to_add) {
+ if(text_to_add.empty())
+ return;
+
if(show_placeholder) {
show_placeholder = false;
text.setString("");
text.setFillColor(sf::Color::White);
}
+
sf::String str = text.getString();
str += text_to_add;
text.setString(str);
+
clear_autocomplete_if_text_not_substring();
if(!updated_search && onTextBeginTypingCallback)
onTextBeginTypingCallback();
updated_search = true;
updated_autocomplete = true;
time_since_search_update.restart();
- needs_update = true;
+ if(str[str.getSize() - 1] == '\n')
+ needs_update = true;
}
bool SearchBar::is_cursor_at_start_of_line() const {