mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 05:28:49 +00:00
improve comments and extract a common function
This commit is contained in:
parent
7e1a3148fb
commit
d2ffdc8986
1 changed files with 19 additions and 23 deletions
42
reader.cpp
42
reader.cpp
|
@ -1653,25 +1653,35 @@ bool compare_completions_by_match_type(const completion_t &a, const completion_t
|
|||
return wcsfilecmp(a.completion.c_str(), b.completion.c_str()) < 0;
|
||||
}
|
||||
|
||||
/* Order completions such that case insensitive completions come first. */
|
||||
static void prioritize_completions(std::vector<completion_t> &comp)
|
||||
/* Determine the best match type */
|
||||
fuzzy_match_type_t get_best_match_type(const std::vector<completion_t> &comp)
|
||||
{
|
||||
/* Determine the best match type */
|
||||
size_t i;
|
||||
fuzzy_match_type_t best_type = fuzzy_match_none;
|
||||
for (i=0; i < comp.size(); i++)
|
||||
for (size_t i=0; i < comp.size(); i++)
|
||||
{
|
||||
const completion_t &el = comp.at(i);
|
||||
if (el.match.type < best_type)
|
||||
{
|
||||
best_type = el.match.type;
|
||||
}
|
||||
}
|
||||
/* For case exact match as best type, make it to lower level as prefix match,
|
||||
because completions with prefix match cannot stay otherwise while they are
|
||||
also candidates of the input along with completion with exact match. */
|
||||
if (best_type == fuzzy_match_exact)
|
||||
{
|
||||
best_type = fuzzy_match_prefix;
|
||||
}
|
||||
return best_type;
|
||||
}
|
||||
|
||||
/* Throw out completions whose match types are not the best. */
|
||||
i = comp.size();
|
||||
/* Order completions such that case insensitive completions come first. */
|
||||
static void prioritize_completions(std::vector<completion_t> &comp)
|
||||
{
|
||||
fuzzy_match_type_t best_type = get_best_match_type(comp);
|
||||
|
||||
/* Throw out completions whose match types are less suitable than the best. */
|
||||
size_t i = comp.size();
|
||||
while (i--)
|
||||
{
|
||||
if (comp.at(i).match.type > best_type)
|
||||
|
@ -1789,21 +1799,7 @@ static bool handle_completions(const std::vector<completion_t> &comp)
|
|||
|
||||
if (!done)
|
||||
{
|
||||
|
||||
/* Determine the type of the best match(es) */
|
||||
fuzzy_match_type_t best_match_type = fuzzy_match_none;
|
||||
for (size_t i=0; i < comp.size(); i++)
|
||||
{
|
||||
const completion_t &el = comp.at(i);
|
||||
if (el.match.type < best_match_type)
|
||||
{
|
||||
best_match_type = el.match.type;
|
||||
}
|
||||
}
|
||||
if (best_match_type == fuzzy_match_exact)
|
||||
{
|
||||
best_match_type = fuzzy_match_prefix;
|
||||
}
|
||||
fuzzy_match_type_t best_match_type = get_best_match_type(comp);
|
||||
|
||||
/* 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;
|
||||
|
@ -1822,7 +1818,7 @@ static bool handle_completions(const std::vector<completion_t> &comp)
|
|||
for (size_t i=0; i < comp.size(); i++)
|
||||
{
|
||||
const completion_t &el = comp.at(i);
|
||||
/* Only use completions with the best match type */
|
||||
/* Ignore completions with less suitable match type than the best. */
|
||||
if (el.match.type > best_match_type)
|
||||
continue;
|
||||
|
||||
|
|
Loading…
Reference in a new issue