Emote Popup Improvements (#1895)

* Put exact matching emotes first

* Close GenericListView on Escape press
This commit is contained in:
Daniel 2020-08-22 17:17:56 -04:00 committed by GitHub
parent 505581ca65
commit 184aba1be7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -17,6 +17,7 @@ namespace {
struct _Emote {
EmotePtr emote;
QString displayName;
QString providerName;
};
@ -25,7 +26,8 @@ namespace {
{
for (auto &&emote : map)
if (emote.first.string.contains(text, Qt::CaseInsensitive))
out.push_back({emote.second, providerName});
out.push_back(
{emote.second, emote.second->name.string, providerName});
}
void addEmojis(std::vector<_Emote> &out, const EmojiMap &map,
@ -34,7 +36,7 @@ namespace {
map.each([&](const QString &, const std::shared_ptr<EmojiData> &emoji) {
for (auto &&shortCode : emoji->shortCodes)
if (shortCode.contains(text, Qt::CaseInsensitive))
out.push_back({emoji->emote, "Emoji"});
out.push_back({emoji->emote, shortCode, "Emoji"});
});
}
} // namespace
@ -92,13 +94,27 @@ void EmoteInputPopup::updateEmotes(const QString &text, ChannelPtr channel)
addEmojis(emotes, getApp()->emotes->emojis.emojis, text);
}
// if there is an exact match, put that emote first
for (int i = 1; i < (int)emotes.size(); i++)
{
auto emoteText = emotes.at(i).displayName;
// test for match or match with colon at start for emotes like ":)"
if (emoteText.compare(text, Qt::CaseInsensitive) == 0 ||
emoteText.compare(":" + text, Qt::CaseInsensitive) == 0)
{
std::iter_swap(emotes.begin(), emotes.begin() + i);
break;
}
}
this->model_.clear();
int count = 0;
for (auto &&emote : emotes)
{
this->model_.addItem(std::make_unique<EmoteInputItem>(
emote.emote, emote.emote->name.string + " - " + emote.providerName,
emote.emote, emote.displayName + " - " + emote.providerName,
this->callback_));
if (count++ == maxEmoteCount)