aboutsummaryrefslogtreecommitdiffhomepage
path: root/reader.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2013-08-31 15:01:02 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2013-08-31 15:01:02 -0700
commitc38a40d1930d0af2f0d078896fe02fd0bee5fabd (patch)
tree2e70a5cbdd863bde7373ffaa9972a0cd5aaa0c10 /reader.cpp
parent23ba7b5bfff9393d222cd8e4a045e3439e24aba1 (diff)
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
Diffstat (limited to 'reader.cpp')
-rw-r--r--reader.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/reader.cpp b/reader.cpp
index 11b45e9d..cd9d9e45 100644
--- a/reader.cpp
+++ b/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 */