From bff015d5b96a69743b4d6347049e1af528b2d869 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 8 Oct 2012 19:14:48 +0200 Subject: [PATCH] WordCompleter: avoid word currently being edited --- src/client.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/client.cc b/src/client.cc index 62c52764..3b3c8a4e 100644 --- a/src/client.cc +++ b/src/client.cc @@ -348,7 +348,7 @@ private: ++begin; String prefix = context.buffer().string(begin, end); - m_completions = complete_word(context, prefix); + m_completions = complete_word(context, prefix, begin); if (m_completions.empty()) return false; @@ -363,7 +363,8 @@ private: } CandidateList complete_word(const Context& context, - const String& prefix) + const String& prefix, + const BufferIterator& pos) { String ex = "\\<\\Q" + prefix + "\\E\\w+\\>"; Regex re(ex.begin(), ex.end()); @@ -372,13 +373,15 @@ private: boost::regex_iterator end; CandidateList result; - while (it != end) + for (; it != end; ++it) { auto& match = (*it)[0]; + if (match.first <= pos and pos < match.second) + continue; + String content = buffer.string(match.first, match.second); if (not contains(result, content)) result.emplace_back(std::move(content)); - ++it; } std::sort(result.begin(), result.end()); return result;