mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-27 20:25:12 +00:00
Final cleanup of history
This commit is contained in:
parent
9ab54030b9
commit
00ad837eb4
3 changed files with 51 additions and 958 deletions
981
history.cpp
981
history.cpp
File diff suppressed because it is too large
Load diff
22
history.h
22
history.h
|
@ -9,6 +9,8 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "pthread.h"
|
#include "pthread.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <deque>
|
||||||
|
#include <utility>
|
||||||
#include <tr1/memory>
|
#include <tr1/memory>
|
||||||
using std::tr1::shared_ptr;
|
using std::tr1::shared_ptr;
|
||||||
|
|
||||||
|
@ -100,14 +102,18 @@ class history_search_t {
|
||||||
|
|
||||||
/** The history in which we are searching */
|
/** The history in which we are searching */
|
||||||
history_t * history;
|
history_t * history;
|
||||||
|
|
||||||
|
/** Our list of previous matches as index, value. The end is the current match. */
|
||||||
|
typedef std::pair<size_t, wcstring> prev_match_t;
|
||||||
|
std::deque<prev_match_t> prev_matches;
|
||||||
|
|
||||||
|
/** Returns yes if a given term is in prev_matches. */
|
||||||
|
bool match_already_made(const wcstring &match) const;
|
||||||
|
|
||||||
/** The search term */
|
/** The search term */
|
||||||
wcstring term;
|
wcstring term;
|
||||||
|
|
||||||
/** Current index into the history */
|
|
||||||
size_t idx;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/** Finds the next search term (forwards in time). Returns true if one was found. */
|
/** Finds the next search term (forwards in time). Returns true if one was found. */
|
||||||
bool go_forwards(void);
|
bool go_forwards(void);
|
||||||
|
@ -122,20 +128,18 @@ public:
|
||||||
void go_to_beginning(void);
|
void go_to_beginning(void);
|
||||||
|
|
||||||
/** Returns the current search result. asserts if there is no current item. */
|
/** Returns the current search result. asserts if there is no current item. */
|
||||||
history_item_t current_item(void) const;
|
wcstring current_item(void) const;
|
||||||
|
|
||||||
/** Constructor */
|
/** Constructor */
|
||||||
history_search_t(history_t &hist, const wcstring &str) :
|
history_search_t(history_t &hist, const wcstring &str) :
|
||||||
history(&hist),
|
history(&hist),
|
||||||
term(str),
|
term(str)
|
||||||
idx()
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/* Default constructor */
|
/* Default constructor */
|
||||||
history_search_t() :
|
history_search_t() :
|
||||||
history(),
|
history(),
|
||||||
term(),
|
term()
|
||||||
idx()
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -1885,8 +1885,8 @@ static void handle_token_history( int forward, int reset )
|
||||||
/* No luck */
|
/* No luck */
|
||||||
data->token_history_buff = wcsdup(L"");
|
data->token_history_buff = wcsdup(L"");
|
||||||
} else {
|
} else {
|
||||||
history_item_t item = data->history_search.current_item();
|
wcstring item = data->history_search.current_item();
|
||||||
data->token_history_buff = wcsdup(item.str().c_str());
|
data->token_history_buff = wcsdup(item.c_str());
|
||||||
}
|
}
|
||||||
current_pos = wcslen(data->token_history_buff);
|
current_pos = wcslen(data->token_history_buff);
|
||||||
|
|
||||||
|
@ -3131,7 +3131,7 @@ wchar_t *reader_readline()
|
||||||
|
|
||||||
wcstring new_text;
|
wcstring new_text;
|
||||||
if (success) {
|
if (success) {
|
||||||
new_text = data->history_search.current_item().str();
|
new_text = data->history_search.current_item();
|
||||||
} else {
|
} else {
|
||||||
new_text = data->search_buff;
|
new_text = data->search_buff;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue