Skip to content

Commit

Permalink
Emote Popup Improvements (Chatterino#1895)
Browse files Browse the repository at this point in the history
* Put exact matching emotes first

* Close GenericListView on Escape press
  • Loading branch information
dnsge authored Aug 22, 2020
1 parent 505581c commit 184aba1
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/widgets/splits/EmoteInputPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace {

struct _Emote {
EmotePtr emote;
QString displayName;
QString providerName;
};

Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 184aba1

Please sign in to comment.