mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-25 20:33:08 +00:00
Make history searching skip the autosuggestion
This commit is contained in:
parent
eeed45da0f
commit
27f2859258
3 changed files with 27 additions and 2 deletions
12
history.cpp
12
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;
|
||||
}
|
||||
|
|
11
history.h
11
history.h
|
@ -12,6 +12,7 @@
|
|||
#include <deque>
|
||||
#include <utility>
|
||||
#include <tr1/memory>
|
||||
#include <set>
|
||||
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);
|
||||
|
||||
|
|
|
@ -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 )
|
||||
|
|
Loading…
Reference in a new issue