Use natural (digit-sequence-aware) sorting for wildcard expansion

Fixes #1993
This commit is contained in:
ridiculousfish
2015-03-23 11:13:26 -07:00
parent 89da09636e
commit 0ecf294d34
4 changed files with 7 additions and 5 deletions

View File

@@ -324,9 +324,9 @@ completion_t &completion_t::operator=(const completion_t &him)
return *this;
}
bool completion_t::is_alphabetically_less_than(const completion_t &a, const completion_t &b)
bool completion_t::is_naturally_less_than(const completion_t &a, const completion_t &b)
{
return a.completion < b.completion;
return wcsfilecmp(a.completion.c_str(), b.completion.c_str()) < 0;
}
bool completion_t::is_alphabetically_equal_to(const completion_t &a, const completion_t &b)

View File

@@ -123,7 +123,9 @@ class completion_t
completion_t &operator=(const completion_t &);
/* Compare two completions. No operating overlaoding to make this always explicit (there's potentially multiple ways to compare completions). */
static bool is_alphabetically_less_than(const completion_t &a, const completion_t &b);
/* "Naturally less than" means in a natural ordering, where digits are treated as numbers. For example, foo10 is naturally greater than foo2 (but alphabetically less than it) */
static bool is_naturally_less_than(const completion_t &a, const completion_t &b);
static bool is_alphabetically_equal_to(const completion_t &a, const completion_t &b);
};

View File

@@ -1923,7 +1923,7 @@ int expand_string(const wcstring &input, std::vector<completion_t> &output, expa
case 1:
{
res = EXPAND_WILDCARD_MATCH;
std::sort(expanded.begin(), expanded.end(), completion_t::is_alphabetically_less_than);
std::sort(expanded.begin(), expanded.end(), completion_t::is_naturally_less_than);
out->insert(out->end(), expanded.begin(), expanded.end());
break;
}

View File

@@ -867,7 +867,7 @@ 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(), completion_t::is_alphabetically_less_than);
sort(l.begin(), l.end(), completion_t::is_naturally_less_than);
l.erase(std::unique(l.begin(), l.end(), completion_t::is_alphabetically_equal_to), l.end());
}