From 7e1a3148fb373fc1c75c2350f1a256b4f06bea1f Mon Sep 17 00:00:00 2001 From: Tony Wang Date: Sun, 18 Aug 2013 10:43:13 +0800 Subject: [PATCH] fixed fish-shell/fish-shell#944 When the completion list includes the exact typed string with other candidates, i.e. completion_t.match.type == fuzzy_match_exact, the other candidates will be removed from the list, as they are not the "best type". This is inconvenient for the user who wants to type and complete commands in the other candidates. The commit is to make the best_type to fuzzy_match_prefix as highest priority, also, when comparing to best_type, the same or higher priority completions can both match. --- reader.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/reader.cpp b/reader.cpp index 80d60fb88..8045467e8 100644 --- a/reader.cpp +++ b/reader.cpp @@ -1665,12 +1665,16 @@ static void prioritize_completions(std::vector &comp) if (el.match.type < best_type) best_type = el.match.type; } + if (best_type == fuzzy_match_exact) + { + best_type = fuzzy_match_prefix; + } /* Throw out completions whose match types are not the best. */ i = comp.size(); while (i--) { - if (comp.at(i).match.type != best_type) + if (comp.at(i).match.type > best_type) { comp.erase(comp.begin() + i); } @@ -1796,13 +1800,17 @@ static bool handle_completions(const std::vector &comp) best_match_type = el.match.type; } } + if (best_match_type == fuzzy_match_exact) + { + best_match_type = fuzzy_match_prefix; + } /* Determine whether we are going to replace the token or not. If any commands of the best type do not require replacement, then ignore all those that want to use replacement */ bool will_replace_token = true; for (size_t i=0; i< comp.size(); i++) { const completion_t &el = comp.at(i); - if (el.match.type == best_match_type && !(el.flags & COMPLETE_REPLACES_TOKEN)) + if (el.match.type <= best_match_type && !(el.flags & COMPLETE_REPLACES_TOKEN)) { will_replace_token = false; break; @@ -1815,7 +1823,7 @@ static bool handle_completions(const std::vector &comp) { const completion_t &el = comp.at(i); /* Only use completions with the best match type */ - if (el.match.type != best_match_type) + if (el.match.type > best_match_type) continue; /* Only use completions that match replace_token */