Preserve current word in word completion if found elsewhere
If occurence count in the buffer if greater that one, do not remove it from the matches.
This commit is contained in:
parent
65c818b859
commit
389308dfd8
|
@ -776,11 +776,13 @@ public:
|
|||
|
||||
String current_word{begin, end};
|
||||
|
||||
auto& word_db = get_word_db(buffer);
|
||||
std::unordered_set<String> matches;
|
||||
auto bufmatches = get_word_db(buffer).find_prefix(prefix);
|
||||
auto bufmatches = word_db.find_prefix(prefix);
|
||||
matches.insert(bufmatches.begin(), bufmatches.end());
|
||||
|
||||
matches.erase(current_word);
|
||||
if (word_db.get_word_occurences(current_word) <= 1)
|
||||
matches.erase(current_word);
|
||||
|
||||
if (other_buffers)
|
||||
{
|
||||
|
|
|
@ -80,6 +80,8 @@ void test_word_db()
|
|||
auto res = word_db.find_prefix("");
|
||||
std::sort(res.begin(), res.end());
|
||||
kak_assert(res == std::vector<String>{ "allo" COMMA "kanaky" COMMA "mutch" COMMA "tchaa" COMMA "tchou" });
|
||||
kak_assert(word_db.get_word_occurences("tchou") == 3);
|
||||
kak_assert(word_db.get_word_occurences("allo") == 1);
|
||||
buffer.erase(buffer.iterator_at({1, 6}), buffer.iterator_at({4, 0}));
|
||||
res = word_db.find_prefix("");
|
||||
std::sort(res.begin(), res.end());
|
||||
|
|
|
@ -112,4 +112,12 @@ std::vector<String> WordDB::find_prefix(const String& prefix)
|
|||
return res;
|
||||
}
|
||||
|
||||
int WordDB::get_word_occurences(const String& word) const
|
||||
{
|
||||
auto it = m_words.find(word);
|
||||
if (it != m_words.end())
|
||||
return it->second;
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ public:
|
|||
WordDB(const Buffer& buffer);
|
||||
|
||||
std::vector<String> find_prefix(const String& prefix);
|
||||
int get_word_occurences(const String& word) const;
|
||||
|
||||
using WordList = std::map<String, int>;
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue
Block a user