summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2015-10-20 13:50:55 +0100
committerMaxime Coste <frrrwww@gmail.com>2015-10-20 13:50:55 +0100
commit2bf391f36d104c1446ab5b72a9c6005fa6f06db9 (patch)
tree353079ada43db2907c9f1bf29a012153558ebfb0 /src
parent9449f763e056badbded390c7a7b96980f8580d8b (diff)
Sort insert completer words by name favoring lower case and then stable sort by rank
Diffstat (limited to 'src')
-rw-r--r--src/insert_completer.cc11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/insert_completer.cc b/src/insert_completer.cc
index ee9ca292..3d15d3f3 100644
--- a/src/insert_completer.cc
+++ b/src/insert_completer.cc
@@ -127,12 +127,19 @@ InsertCompletion complete_word(const Buffer& buffer, ByteCoord cursor_pos)
}
}
unordered_erase(matches, StringView{prefix});
+ // Sort by word, favoring lowercase
std::sort(matches.begin(), matches.end(),
[](const RankedWordAndBuffer& lhs, const RankedWordAndBuffer& rhs) {
- return lhs.word < rhs.word;
+ return std::lexicographical_compare(
+ lhs.word.begin(), lhs.word.end(), rhs.word.begin(), rhs.word.end(),
+ [](char a, char b) {
+ const bool low_a = islower(a), low_b = islower(b);
+ return low_a == low_b ? a < b : low_a;
+ });
});
matches.erase(std::unique(matches.begin(), matches.end()), matches.end());
- std::sort(matches.begin(), matches.end());
+ // Stable sort by rank to preserve by word sorting
+ std::stable_sort(matches.begin(), matches.end());
const auto longest = std::accumulate(matches.begin(), matches.end(), 0_char,
[](const CharCount& lhs, const RankedWordAndBuffer& rhs)