diff --git a/src/entrybox.cpp b/src/entrybox.cpp index 3fa0b4f..aadffc5 100644 --- a/src/entrybox.cpp +++ b/src/entrybox.cpp @@ -9,12 +9,8 @@ EntryBox::Entry::Entry(const std::string &content, std::functionon_activate) { - auto &history = EntryBox::entry_histories[get_placeholder_text()]; - auto text = get_text(); - if(!text.empty() && (history.empty() || *history.begin() != text)) - history.emplace(history.begin(), text); - selected_history = -1; - this->on_activate(text); + update_history(); + this->on_activate(get_text()); } }); signal_changed().connect([this] { @@ -57,6 +53,14 @@ EntryBox::Entry::Entry(const std::string &content, std::function on_activate_) : Gtk::Button(label), on_activate(std::move(on_activate_)) { set_focus_on_click(false); signal_clicked().connect([this]() { diff --git a/src/entrybox.hpp b/src/entrybox.hpp index d56ce2f..869e773 100644 --- a/src/entrybox.hpp +++ b/src/entrybox.hpp @@ -13,6 +13,9 @@ public: Entry(const std::string &content = "", std::function on_activate_ = nullptr); std::function on_activate; + /// Only the default activation on an entry will update its history. + void update_history(); + private: long selected_history; std::string last_content; diff --git a/src/window.cpp b/src/window.cpp index 718a746..3dfb72e 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -2102,8 +2102,9 @@ void Window::search_and_replace_entry() { }); auto search_entry_it = EntryBox::get().entries.begin(); search_entry_it->set_placeholder_text("Find"); - search_entry_it->signal_key_press_event().connect([this](GdkEventKey *event) { + search_entry_it->signal_key_press_event().connect([this, search_entry_it](GdkEventKey *event) { if((event->keyval == GDK_KEY_Return || event->keyval == GDK_KEY_KP_Enter) && (event->state & GDK_SHIFT_MASK) > 0) { + search_entry_it->update_history(); if(focused_view) focused_view->search_backward(); } @@ -2115,15 +2116,18 @@ void Window::search_and_replace_entry() { focused_view->search_highlight(search_entry_it->get_text(), case_sensitive_search, regex_search); }); - EntryBox::get().entries.emplace_back(last_replace, [this](const std::string &content) { + EntryBox::get().entries.emplace_back(last_replace, [this, search_entry_it](const std::string &content) { + search_entry_it->update_history(); if(focused_view) focused_view->replace_forward(content); }); auto replace_entry_it = EntryBox::get().entries.begin(); replace_entry_it++; replace_entry_it->set_placeholder_text("Replace"); - replace_entry_it->signal_key_press_event().connect([this, replace_entry_it](GdkEventKey *event) { + replace_entry_it->signal_key_press_event().connect([this, search_entry_it, replace_entry_it](GdkEventKey *event) { if((event->keyval == GDK_KEY_Return || event->keyval == GDK_KEY_KP_Enter) && (event->state & GDK_SHIFT_MASK) > 0) { + search_entry_it->update_history(); + replace_entry_it->update_history(); if(focused_view) focused_view->replace_backward(replace_entry_it->get_text()); } @@ -2133,22 +2137,28 @@ void Window::search_and_replace_entry() { last_replace = replace_entry_it->get_text(); }); - EntryBox::get().buttons.emplace_back("↑", [this]() { + EntryBox::get().buttons.emplace_back("↑", [this, search_entry_it]() { + search_entry_it->update_history(); if(focused_view) focused_view->search_backward(); }); EntryBox::get().buttons.back().set_tooltip_text("Find Previous\n\nShortcut: Shift+Enter in the Find entry field"); - EntryBox::get().buttons.emplace_back("⇄", [this, replace_entry_it]() { + EntryBox::get().buttons.emplace_back("⇄", [this, search_entry_it, replace_entry_it]() { + search_entry_it->update_history(); + replace_entry_it->update_history(); if(focused_view) focused_view->replace_forward(replace_entry_it->get_text()); }); EntryBox::get().buttons.back().set_tooltip_text("Replace Next\n\nShortcut: Enter in the Replace entry field"); - EntryBox::get().buttons.emplace_back("↓", [this]() { + EntryBox::get().buttons.emplace_back("↓", [this, search_entry_it]() { + search_entry_it->update_history(); if(focused_view) focused_view->search_forward(); }); EntryBox::get().buttons.back().set_tooltip_text("Find Next\n\nShortcut: Enter in the Find entry field"); - EntryBox::get().buttons.emplace_back("Replace All", [this, replace_entry_it]() { + EntryBox::get().buttons.emplace_back("Replace All", [this, search_entry_it, replace_entry_it]() { + search_entry_it->update_history(); + replace_entry_it->update_history(); if(focused_view) focused_view->replace_all(replace_entry_it->get_text()); });