mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Emote Popup Improvements (#1895)
* Put exact matching emotes first * Close GenericListView on Escape press
This commit is contained in:
parent
505581ca65
commit
184aba1be7
1 changed files with 19 additions and 3 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue