aboutsummaryrefslogtreecommitdiffhomepage
path: root/history.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-02-06 10:52:13 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-02-06 10:52:13 -0800
commit067dff84891b2c0fc45c5e1bbe1e6f04fdd6040e (patch)
tree977ea48eaf21f7c16c4ab97cb018b11d2baa129d /history.cpp
parent7d3151191d24efd296f34068be04a1f7c3cff633 (diff)
Initial stab at autosuggestions
Diffstat (limited to 'history.cpp')
-rw-r--r--history.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/history.cpp b/history.cpp
index dd9489d8..91014075 100644
--- a/history.cpp
+++ b/history.cpp
@@ -19,6 +19,7 @@
#include "fallback.h"
#include "util.h"
+#include "sanity.h"
#include "wutil.h"
#include "history.h"
@@ -110,6 +111,23 @@ history_item_t::history_item_t(const wcstring &str, time_t when) : contents(str)
{
}
+bool history_item_t::matches_search(const wcstring &term, enum history_search_type_t type) const {
+ switch (type) {
+
+ case HISTORY_SEARCH_TYPE_CONTAINS:
+ /* We consider equal strings to NOT match a contains search (so that you don't have to see history equal to what you typed). The length check ensures that. */
+ return contents.size() > term.size() && contents.find(term) != wcstring::npos;
+
+ case HISTORY_SEARCH_TYPE_PREFIX:
+ /* We consider equal strings to match a prefix search, so that autosuggest will allow suggesting what you've typed */
+ return string_prefixes_string(term, contents);
+
+ default:
+ sanity_lose();
+ return false;
+ }
+}
+
bool history_lru_node_t::write_to_file(FILE *f) const {
wcstring escaped = key;
escape_newlines(escaped);
@@ -372,7 +390,7 @@ bool history_search_t::go_backwards() {
}
/* Look for a term that matches and that we haven't seen before */
- if (item.matches_search(term) && ! match_already_made(item.str())) {
+ if (item.matches_search(term, search_type) && ! match_already_made(item.str())) {
prev_matches.push_back(prev_match_t(idx, item.str()));
return true;
}