aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-08-27 01:40:27 +0200
committerdec05eba <dec05eba@protonmail.com>2021-08-27 01:40:27 +0200
commitd1805b49acdbd6026da81ef547cc20497c6c6c6e (patch)
tree4640a7c7e8b2b4873b6b060e9078fbf483a08ad3
parent51aa9384f7cf3ba33430ab7cade60ccdfbe06943 (diff)
Set search input to selected item title when pressing tab
-rw-r--r--README.md1
-rw-r--r--include/SearchBar.hpp1
-rw-r--r--src/QuickMedia.cpp57
-rw-r--r--src/SearchBar.cpp7
4 files changed, 52 insertions, 14 deletions
diff --git a/README.md b/README.md
index 1b3e16c..9a46fc1 100644
--- a/README.md
+++ b/README.md
@@ -60,6 +60,7 @@ Type text and then wait and QuickMedia will automatically search.\
`Ctrl+C`: Copy the text in the selected item to your clipboard.\
`Ctrl+V`: Paste clipboard content into the search bar.\
`Ctrl+I`: Select which url in the selected item to open in a browser.\
+`Tab`: Set search input to the title of the selected item.\
`Ctrl+Enter`: Submit search ignoring the selected item. Only works for matrix room directory page and matrix invites page.
### Video controls
`mpv` controls apply in general, see https://mpv.io/manual/master/#interactive-control.\
diff --git a/include/SearchBar.hpp b/include/SearchBar.hpp
index a888ffb..528327e 100644
--- a/include/SearchBar.hpp
+++ b/include/SearchBar.hpp
@@ -27,6 +27,7 @@ namespace QuickMedia {
void update();
void onWindowResize(const sf::Vector2f &window_size);
void clear();
+ void set_text(const std::string &text);
void append_text(const std::string &text_to_add);
void set_position(sf::Vector2f pos);
void set_editable(bool editable);
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index f7d35d9..f11b69f 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -1770,6 +1770,47 @@ namespace QuickMedia {
}
}
+ static void copy_body_item_text_to_clipboard(BodyItem *body_item) {
+ if(!body_item)
+ return;
+
+ std::string title = body_item->get_title();
+ std::string author = body_item->get_author();
+ std::string description = body_item->get_description();
+
+ std::string clipboard = std::move(title);
+
+ if(!author.empty()) {
+ if(!clipboard.empty())
+ clipboard += '\n';
+ clipboard += std::move(author);
+ }
+
+ if(!description.empty()) {
+ if(!clipboard.empty())
+ clipboard += '\n';
+ clipboard += std::move(description);
+ }
+
+ if(!clipboard.empty())
+ sf::Clipboard::setString(sf::String::fromUtf8(clipboard.begin(), clipboard.end()));
+ }
+
+ static void set_search_bar_to_body_item_text(BodyItem *body_item, SearchBar *search_bar) {
+ if(!body_item || !search_bar)
+ return;
+
+ if(!body_item->get_title().empty()) {
+ search_bar->set_text(body_item->get_title());
+ return;
+ }
+
+ if(!body_item->get_author().empty()) {
+ search_bar->set_text(body_item->get_author());
+ return;
+ }
+ }
+
bool Program::page_loop(std::vector<Tab> &tabs, int start_tab_index, PageLoopSubmitHandler after_submit_handler) {
if(tabs.empty()) {
show_notification("QuickMedia", "No tabs provided!", Urgency::CRITICAL);
@@ -2153,23 +2194,13 @@ namespace QuickMedia {
}
}
} else if(event.key.code == sf::Keyboard::C && event.key.control) {
- BodyItem *selected_item = tabs[selected_tab].body->get_selected();
- if(selected_item) {
- std::string title = selected_item->get_title();
- std::string description = selected_item->get_description();
- std::string clipboard = std::move(title);
- if(!description.empty()) {
- if(!clipboard.empty())
- clipboard += '\n';
- clipboard += std::move(description);
- }
- if(!clipboard.empty())
- sf::Clipboard::setString(sf::String::fromUtf8(clipboard.begin(), clipboard.end()));
- }
+ copy_body_item_text_to_clipboard(tabs[selected_tab].body->get_selected());
} else if(event.key.code == sf::Keyboard::I && event.key.control) {
BodyItem *selected_item = tabs[selected_tab].body->get_selected();
if(show_info_page(selected_item, false))
redraw = true;
+ } else if(event.key.code == sf::Keyboard::Tab && !event.key.control) {
+ set_search_bar_to_body_item_text(tabs[selected_tab].body->get_selected(), tabs[selected_tab].search_bar.get());
}
}
}
diff --git a/src/SearchBar.cpp b/src/SearchBar.cpp
index 31e54fb..5b2d6ec 100644
--- a/src/SearchBar.cpp
+++ b/src/SearchBar.cpp
@@ -221,6 +221,11 @@ namespace QuickMedia {
backspace_pressed = false;
}
+ void SearchBar::set_text(const std::string &text) {
+ clear();
+ append_text(text);
+ }
+
void SearchBar::append_text(const std::string &text_to_add) {
if(text_to_add.empty())
return;
@@ -232,7 +237,7 @@ namespace QuickMedia {
}
sf::String str = text.getString();
- str += text_to_add;
+ str += sf::String::fromUtf8(text_to_add.begin(), text_to_add.end());;
text.setString(str);
if(!updated_search) {