Add input completion test suite (#4644)

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
Daniel Sage
2023-05-21 06:10:49 -04:00
committed by GitHub
parent e9f300b765
commit 51f2c4d1c0
24 changed files with 514 additions and 63 deletions
+38 -30
View File
@@ -17,12 +17,7 @@
namespace {
using namespace chatterino;
struct CompletionEmote {
EmotePtr emote;
QString displayName;
QString providerName;
};
using namespace chatterino::detail;
void addEmotes(std::vector<CompletionEmote> &out, const EmoteMap &map,
const QString &text, const QString &providerName)
@@ -53,33 +48,18 @@ void addEmojis(std::vector<CompletionEmote> &out, const EmojiMap &map,
} // namespace
namespace chatterino {
namespace chatterino::detail {
InputCompletionPopup::InputCompletionPopup(QWidget *parent)
: BasePopup({BasePopup::EnableCustomFrame, BasePopup::Frameless,
BasePopup::DontFocus, BaseWindow::DisableLayoutSave},
parent)
, model_(this)
{
this->initLayout();
QObject::connect(&this->redrawTimer_, &QTimer::timeout, this, [this] {
if (this->isVisible())
{
this->ui_.listView->doItemsLayout();
}
});
this->redrawTimer_.setInterval(33);
}
void InputCompletionPopup::updateEmotes(const QString &text, ChannelPtr channel)
std::vector<CompletionEmote> buildCompletionEmoteList(const QString &text,
ChannelPtr channel)
{
std::vector<CompletionEmote> emotes;
auto *app = getIApp();
auto *tc = dynamic_cast<TwitchChannel *>(channel.get());
// returns true also for special Twitch channels (/live, /mentions, /whispers, etc.)
if (channel->isTwitchChannel())
{
if (auto user = getApp()->accounts->twitch.getCurrent())
if (auto user = app->getAccounts()->twitch.getCurrent())
{
// Twitch Emotes available globally
auto emoteData = user->accessEmotes();
@@ -115,21 +95,21 @@ void InputCompletionPopup::updateEmotes(const QString &text, ChannelPtr channel)
}
}
if (auto bttvG = getApp()->twitch->getBttvEmotes().emotes())
if (auto bttvG = app->getTwitch()->getBttvEmotes().emotes())
{
addEmotes(emotes, *bttvG, text, "Global BetterTTV");
}
if (auto ffzG = getApp()->twitch->getFfzEmotes().emotes())
if (auto ffzG = app->getTwitch()->getFfzEmotes().emotes())
{
addEmotes(emotes, *ffzG, text, "Global FrankerFaceZ");
}
if (auto seventvG = getApp()->twitch->getSeventvEmotes().globalEmotes())
if (auto seventvG = app->getTwitch()->getSeventvEmotes().globalEmotes())
{
addEmotes(emotes, *seventvG, text, "Global 7TV");
}
}
addEmojis(emotes, getApp()->emotes->emojis.emojis, text);
addEmojis(emotes, app->getEmotes()->getEmojis()->getEmojis(), text);
// if there is an exact match, put that emote first
for (size_t i = 1; i < emotes.size(); i++)
@@ -147,6 +127,34 @@ void InputCompletionPopup::updateEmotes(const QString &text, ChannelPtr channel)
}
}
return emotes;
}
} // namespace chatterino::detail
namespace chatterino {
InputCompletionPopup::InputCompletionPopup(QWidget *parent)
: BasePopup({BasePopup::EnableCustomFrame, BasePopup::Frameless,
BasePopup::DontFocus, BaseWindow::DisableLayoutSave},
parent)
, model_(this)
{
this->initLayout();
QObject::connect(&this->redrawTimer_, &QTimer::timeout, this, [this] {
if (this->isVisible())
{
this->ui_.listView->doItemsLayout();
}
});
this->redrawTimer_.setInterval(33);
}
void InputCompletionPopup::updateEmotes(const QString &text, ChannelPtr channel)
{
auto emotes = detail::buildCompletionEmoteList(text, std::move(channel));
this->model_.clear();
int count = 0;
@@ -5,12 +5,29 @@
#include <functional>
#include <memory>
#include <vector>
namespace chatterino {
class Channel;
using ChannelPtr = std::shared_ptr<Channel>;
struct Emote;
using EmotePtr = std::shared_ptr<const Emote>;
namespace detail {
struct CompletionEmote {
EmotePtr emote;
QString displayName;
QString providerName;
};
std::vector<CompletionEmote> buildCompletionEmoteList(const QString &text,
ChannelPtr channel);
} // namespace detail
class GenericListView;
class InputCompletionPopup : public BasePopup