From 6663d50d958fc6b719190e0db492ceda15215161 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 17 Nov 2014 20:15:54 +0000 Subject: [PATCH] Tweak option completion behaviour --- src/insert_completer.cc | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/insert_completer.cc b/src/insert_completer.cc index 812511d46..1e57afcbc 100644 --- a/src/insert_completer.cc +++ b/src/insert_completer.cc @@ -193,22 +193,17 @@ InsertCompletion complete_option(const Buffer& buffer, ByteCoord cursor_pos, }) != changes.end()) return {}; - ByteCount longest_completion = 0; - for (auto it = opt.begin() + 1; it != opt.end(); ++it) - longest_completion = std::max(longest_completion, it->length()); - - if (cursor_pos.line == coord.line and cursor_pos.column >= coord.column and - buffer.distance(coord, cursor_pos) < longest_completion) + if (cursor_pos.line == coord.line and cursor_pos.column >= coord.column) { + StringView prefix = buffer[coord.line].substr( + coord.column, cursor_pos.column - coord.column); + ComplAndDescList res; for (auto it = opt.begin() + 1; it != opt.end(); ++it) { - size_t pos = it->find_first_of("@"); - if (pos != String::npos) - res.emplace_back(it->substr(0_byte, (int)pos), - it->substr(ByteCount{(int)pos+1})); - else - res.emplace_back(*it, ""); + auto splitted = split(*it, '@'); + if (not splitted.empty() and prefix_match(splitted[0], prefix)) + res.emplace_back(splitted[0], splitted.size() > 1 ? splitted[1] : ""); } return { coord, end, std::move(res), timestamp }; }