From 64c58e724ad1610ba3bfcfcfc46c21ed0f47af1d Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 15 Feb 2020 15:49:06 +0100 Subject: [PATCH] Use same sorting method in emote popup as in the completion model Fixes #1549 --- CHANGELOG.md | 4 ++++ src/common/CompletionModel.cpp | 19 ++++++++++++------- src/common/CompletionModel.hpp | 2 ++ src/widgets/dialogs/EmotePopup.cpp | 4 +++- 4 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..6c427d8f3 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,4 @@ +# Changelog + +## Unversioned +- Minor: Emotes in the emote popup are now sorted in the same order as the tab completion (#1549) diff --git a/src/common/CompletionModel.cpp b/src/common/CompletionModel.cpp index 4866e8a24..6cb3bc800 100644 --- a/src/common/CompletionModel.cpp +++ b/src/common/CompletionModel.cpp @@ -38,13 +38,7 @@ bool CompletionModel::TaggedString::operator<(const TaggedString &that) const return this->isEmote(); } - // try comparing insensitively, if they are the same then senstively - // (fixes order of LuL and LUL) - int k = QString::compare(this->string, that.string, Qt::CaseInsensitive); - if (k == 0) - return this->string > that.string; - - return k < 0; + return CompletionModel::compareStrings(this->string, that.string); } // @@ -191,4 +185,15 @@ void CompletionModel::refresh(const QString &prefix, bool isFirstWord) } } +bool CompletionModel::compareStrings(const QString &a, const QString &b) +{ + // try comparing insensitively, if they are the same then senstively + // (fixes order of LuL and LUL) + int k = QString::compare(a, b, Qt::CaseInsensitive); + if (k == 0) + return a > b; + + return k < 0; +} + } // namespace chatterino diff --git a/src/common/CompletionModel.hpp b/src/common/CompletionModel.hpp index 321929e78..2ce374394 100644 --- a/src/common/CompletionModel.hpp +++ b/src/common/CompletionModel.hpp @@ -49,6 +49,8 @@ public: void refresh(const QString &prefix, bool isFirstWord = false); + static bool compareStrings(const QString &a, const QString &b); + private: TaggedString createUser(const QString &str); diff --git a/src/widgets/dialogs/EmotePopup.cpp b/src/widgets/dialogs/EmotePopup.cpp index c000e3ec5..9e0911cb7 100644 --- a/src/widgets/dialogs/EmotePopup.cpp +++ b/src/widgets/dialogs/EmotePopup.cpp @@ -1,6 +1,7 @@ #include "EmotePopup.hpp" #include "Application.hpp" +#include "common/CompletionModel.hpp" #include "controllers/accounts/AccountController.hpp" #include "debug/Benchmark.hpp" #include "messages/Message.hpp" @@ -37,7 +38,8 @@ namespace { std::sort(vec.begin(), vec.end(), [](const std::pair &l, const std::pair &r) { - return l.first.string < r.first.string; + return CompletionModel::compareStrings( + l.first.string, r.first.string); }); for (const auto &emote : vec) {