mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 04:43:10 +00:00
Adjust prefix completions to sort alphabetically instead of by length.
Other completions are still sorted by length. https://github.com/fish-shell/fish-shell/issues/923
This commit is contained in:
parent
23ba7b5bff
commit
c38a40d193
5 changed files with 23 additions and 31 deletions
24
complete.cpp
24
complete.cpp
|
@ -312,20 +312,6 @@ completion_t &completion_t::operator=(const completion_t &him)
|
|||
return *this;
|
||||
}
|
||||
|
||||
bool completion_t::operator < (const completion_t& rhs) const
|
||||
{
|
||||
return this->completion < rhs.completion;
|
||||
}
|
||||
|
||||
bool completion_t::operator == (const completion_t& rhs) const
|
||||
{
|
||||
return this->completion == rhs.completion;
|
||||
}
|
||||
|
||||
bool completion_t::operator != (const completion_t& rhs) const
|
||||
{
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
||||
wcstring_list_t completions_to_wcstring_list(const std::vector<completion_t> &list)
|
||||
{
|
||||
|
@ -338,11 +324,17 @@ wcstring_list_t completions_to_wcstring_list(const std::vector<completion_t> &li
|
|||
return strings;
|
||||
}
|
||||
|
||||
void sort_completions(std::vector<completion_t> &completions)
|
||||
bool completion_t::is_alphabetically_less_than(const completion_t &a, const completion_t &b)
|
||||
{
|
||||
std::sort(completions.begin(), completions.end());
|
||||
return a.completion < b.completion;
|
||||
}
|
||||
|
||||
bool completion_t::is_alphabetically_equal_to(const completion_t &a, const completion_t &b)
|
||||
{
|
||||
return a.completion == b.completion;
|
||||
}
|
||||
|
||||
|
||||
/** Class representing an attempt to compute completions */
|
||||
class completer_t
|
||||
{
|
||||
|
|
12
complete.h
12
complete.h
|
@ -127,11 +127,10 @@ public:
|
|||
completion_t(const wcstring &comp, const wcstring &desc = L"", string_fuzzy_match_t match = string_fuzzy_match_t(fuzzy_match_exact), int flags_val = 0);
|
||||
completion_t(const completion_t &);
|
||||
completion_t &operator=(const completion_t &);
|
||||
|
||||
/* The following are needed for sorting and uniquing completions */
|
||||
bool operator < (const completion_t& rhs) const;
|
||||
bool operator == (const completion_t& rhs) const;
|
||||
bool operator != (const completion_t& rhs) const;
|
||||
|
||||
/* Compare two completions. No operating overlaoding to make this always explicit (there's potentially multiple ways to complare completions). */
|
||||
static bool is_alphabetically_less_than(const completion_t &a, const completion_t &b);
|
||||
static bool is_alphabetically_equal_to(const completion_t &a, const completion_t &b);
|
||||
};
|
||||
|
||||
enum
|
||||
|
@ -146,9 +145,6 @@ typedef uint32_t completion_request_flags_t;
|
|||
/** Given a list of completions, returns a list of their completion fields */
|
||||
wcstring_list_t completions_to_wcstring_list(const std::vector<completion_t> &completions);
|
||||
|
||||
/** Sorts a list of completions */
|
||||
void sort_completions(std::vector<completion_t> &completions);
|
||||
|
||||
/**
|
||||
|
||||
Add a completion.
|
||||
|
|
|
@ -1766,7 +1766,7 @@ int expand_string(const wcstring &input, std::vector<completion_t> &output, expa
|
|||
case 1:
|
||||
{
|
||||
res = EXPAND_WILDCARD_MATCH;
|
||||
sort_completions(expanded);
|
||||
std::sort(expanded.begin(), expanded.end(), completion_t::is_alphabetically_less_than);
|
||||
out->insert(out->end(), expanded.begin(), expanded.end());
|
||||
break;
|
||||
}
|
||||
|
|
1
path.cpp
1
path.cpp
|
@ -367,6 +367,7 @@ bool path_get_config(wcstring &path)
|
|||
return ! result.empty();
|
||||
}
|
||||
|
||||
__attribute__((unused))
|
||||
static void replace_all(wcstring &str, const wchar_t *needle, const wchar_t *replacement)
|
||||
{
|
||||
size_t needle_len = wcslen(needle);
|
||||
|
|
15
reader.cpp
15
reader.cpp
|
@ -802,8 +802,8 @@ bool reader_data_t::expand_abbreviation_as_necessary(size_t cursor_backtrack)
|
|||
/** Sorts and remove any duplicate completions in the list. */
|
||||
static void sort_and_make_unique(std::vector<completion_t> &l)
|
||||
{
|
||||
sort(l.begin(), l.end());
|
||||
l.erase(std::unique(l.begin(), l.end()), l.end());
|
||||
sort(l.begin(), l.end(), completion_t::is_alphabetically_less_than);
|
||||
l.erase(std::unique(l.begin(), l.end(), completion_t::is_alphabetically_equal_to), l.end());
|
||||
}
|
||||
|
||||
|
||||
|
@ -1642,11 +1642,14 @@ static bool reader_can_replace(const wcstring &in, int flags)
|
|||
/* Compare two completions, ordering completions with better match types first */
|
||||
bool compare_completions_by_match_type(const completion_t &a, const completion_t &b)
|
||||
{
|
||||
/* Compare match types */
|
||||
int match_compare = a.match.compare(b.match);
|
||||
if (match_compare != 0)
|
||||
/* Compare match types, unless both completions are prefix (#923) in which case we always want to compare them alphabetically */
|
||||
if (a.match.type != fuzzy_match_prefix || b.match.type != fuzzy_match_prefix)
|
||||
{
|
||||
return match_compare < 0;
|
||||
int match_compare = a.match.compare(b.match);
|
||||
if (match_compare != 0)
|
||||
{
|
||||
return match_compare < 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Compare using file comparison */
|
||||
|
|
Loading…
Reference in a new issue