summaryrefslogtreecommitdiff
path: root/src/input_handler.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2014-01-16 22:07:42 +0000
committerMaxime Coste <frrrwww@gmail.com>2014-01-16 22:07:42 +0000
commit997aadd33fc0efada5011e95f99df87b8b6b88b0 (patch)
tree84fc415461f93cfb28ae47918bdd9d1ffa835415 /src/input_handler.cc
parenta6b386e9b8e9acba78298131fc8332953b9cc963 (diff)
Word completion use a WordDB stored as a buffer value.
Diffstat (limited to 'src/input_handler.cc')
-rw-r--r--src/input_handler.cc33
1 files changed, 18 insertions, 15 deletions
diff --git a/src/input_handler.cc b/src/input_handler.cc
index 30c31413..99121ba9 100644
--- a/src/input_handler.cc
+++ b/src/input_handler.cc
@@ -10,6 +10,7 @@
#include "client.hh"
#include "color_registry.hh"
#include "file.hh"
+#include "word_db.hh"
#include <unordered_map>
@@ -707,6 +708,15 @@ public:
}
using StringList = std::vector<String>;
+ static WordDB& get_word_db(const Buffer& buffer)
+ {
+ static const ValueId word_db_id = ValueId::get_free_id();
+ Value& cache_val = buffer.values()[word_db_id];
+ if (not cache_val)
+ cache_val = Value(WordDB{buffer});
+ return cache_val.as<WordDB>();
+ }
+
template<bool other_buffers>
BufferCompletion complete_word(const Buffer& buffer, BufferCoord cursor_pos)
{
@@ -721,31 +731,24 @@ public:
if (not is_word(*begin))
++begin;
- String ex = R"(\<\Q)" + String{begin, end} + R"(\E\w+\>)";
- Regex re(ex.begin(), ex.end());
- using RegexIt = boost::regex_iterator<BufferIterator>;
+ String prefix{begin, end};
+
std::unordered_set<String> matches;
- for (RegexIt it(buffer.begin(), buffer.end(), re), re_end; it != re_end; ++it)
- {
- auto& match = (*it)[0];
- if (match.first <= pos and pos < match.second)
- continue;
- matches.insert(String{match.first, match.second});
- }
+ auto bufmatches = get_word_db(buffer).find_prefix(prefix);
+ matches.insert(bufmatches.begin(), bufmatches.end());
+
if (other_buffers)
{
for (const auto& buf : BufferManager::instance())
{
if (buf.get() == &buffer)
continue;
- for (RegexIt it(buf->begin(), buf->end(), re), re_end; it != re_end; ++it)
- {
- auto& match = (*it)[0];
- matches.insert(String{match.first, match.second});
- }
+ bufmatches = get_word_db(*buf).find_prefix(prefix);
+ matches.insert(bufmatches.begin(), bufmatches.end());
}
}
+ matches.erase(prefix);
CandidateList result;
std::copy(make_move_iterator(matches.begin()),
make_move_iterator(matches.end()),