From 2bf391f36d104c1446ab5b72a9c6005fa6f06db9 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 20 Oct 2015 13:50:55 +0100 Subject: [PATCH] Sort insert completer words by name favoring lower case and then stable sort by rank --- src/insert_completer.cc | 11 +++++++++-- 1 file 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)