Emote Popup Improvements (#1895)
* Put exact matching emotes first * Close GenericListView on Escape press
This commit is contained in:
@@ -17,6 +17,7 @@ namespace {
|
|||||||
|
|
||||||
struct _Emote {
|
struct _Emote {
|
||||||
EmotePtr emote;
|
EmotePtr emote;
|
||||||
|
QString displayName;
|
||||||
QString providerName;
|
QString providerName;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -25,7 +26,8 @@ namespace {
|
|||||||
{
|
{
|
||||||
for (auto &&emote : map)
|
for (auto &&emote : map)
|
||||||
if (emote.first.string.contains(text, Qt::CaseInsensitive))
|
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,
|
void addEmojis(std::vector<_Emote> &out, const EmojiMap &map,
|
||||||
@@ -34,7 +36,7 @@ namespace {
|
|||||||
map.each([&](const QString &, const std::shared_ptr<EmojiData> &emoji) {
|
map.each([&](const QString &, const std::shared_ptr<EmojiData> &emoji) {
|
||||||
for (auto &&shortCode : emoji->shortCodes)
|
for (auto &&shortCode : emoji->shortCodes)
|
||||||
if (shortCode.contains(text, Qt::CaseInsensitive))
|
if (shortCode.contains(text, Qt::CaseInsensitive))
|
||||||
out.push_back({emoji->emote, "Emoji"});
|
out.push_back({emoji->emote, shortCode, "Emoji"});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
@@ -92,13 +94,27 @@ void EmoteInputPopup::updateEmotes(const QString &text, ChannelPtr channel)
|
|||||||
addEmojis(emotes, getApp()->emotes->emojis.emojis, text);
|
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();
|
this->model_.clear();
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (auto &&emote : emotes)
|
for (auto &&emote : emotes)
|
||||||
{
|
{
|
||||||
this->model_.addItem(std::make_unique<EmoteInputItem>(
|
this->model_.addItem(std::make_unique<EmoteInputItem>(
|
||||||
emote.emote, emote.emote->name.string + " - " + emote.providerName,
|
emote.emote, emote.displayName + " - " + emote.providerName,
|
||||||
this->callback_));
|
this->callback_));
|
||||||
|
|
||||||
if (count++ == maxEmoteCount)
|
if (count++ == maxEmoteCount)
|
||||||
|
|||||||
Reference in New Issue
Block a user