From 27f2859258921eadf6b6c7ecfc494079dd8e5e11 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Mon, 6 Feb 2012 11:52:24 -0800 Subject: [PATCH] Make history searching skip the autosuggestion --- history.cpp | 12 +++++++++++- history.h | 11 ++++++++++- reader.cpp | 6 ++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/history.cpp b/history.cpp index 910140751..85374aedc 100644 --- a/history.cpp +++ b/history.cpp @@ -362,6 +362,15 @@ void history_t::load_old_if_needed(void) signal_unblock(); } +void history_search_t::skip_matches(const wcstring_list_t &skips) { + external_skips = skips; + std::sort(external_skips.begin(), external_skips.end()); +} + +bool history_search_t::should_skip_match(const wcstring &str) const { + return std::binary_search(external_skips.begin(), external_skips.end(), str); +} + bool history_search_t::go_forwards() { /* Pop the top index (if more than one) and return if we have any left */ if (prev_matches.size() > 1) { @@ -390,7 +399,8 @@ bool history_search_t::go_backwards() { } /* Look for a term that matches and that we haven't seen before */ - if (item.matches_search(term, search_type) && ! match_already_made(item.str())) { + const wcstring &str = item.str(); + if (item.matches_search(term, search_type) && ! match_already_made(str) && ! should_skip_match(str)) { prev_matches.push_back(prev_match_t(idx, item.str())); return true; } diff --git a/history.h b/history.h index 8514fc36f..b4fbb326c 100644 --- a/history.h +++ b/history.h @@ -12,6 +12,7 @@ #include #include #include +#include using std::tr1::shared_ptr; enum history_search_type_t { @@ -126,9 +127,17 @@ class history_search_t { /** The search term */ wcstring term; - + + /** Additional strings to skip (sorted) */ + wcstring_list_t external_skips; + + bool should_skip_match(const wcstring &str) const; + public: + /** Sets additional string matches to skip */ + void skip_matches(const wcstring_list_t &skips); + /** Finds the next search term (forwards in time). Returns true if one was found. */ bool go_forwards(void); diff --git a/reader.cpp b/reader.cpp index 39faaabfb..0cc1638a0 100644 --- a/reader.cpp +++ b/reader.cpp @@ -3088,6 +3088,12 @@ const wchar_t *reader_readline() data->search_buff.append(data->command_line); data->history_search = history_search_t(*data->history, data->search_buff, HISTORY_SEARCH_TYPE_CONTAINS); + + /* Skip the autosuggestion as history */ + const wcstring &suggest = data->autosuggestion; + if (! suggest.empty()) { + data->history_search.skip_matches(wcstring_list_t(&suggest, 1 + &suggest)); + } } switch( data->search_mode )