Refactor Tab completion for Twitch commands (#3144)
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "controllers/commands/CommandController.hpp"
|
||||
#include "debug/Benchmark.hpp"
|
||||
#include "providers/twitch/TwitchChannel.hpp"
|
||||
#include "providers/twitch/TwitchCommon.hpp"
|
||||
#include "providers/twitch/TwitchIrcServer.hpp"
|
||||
#include "singletons/Emotes.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
@@ -85,21 +86,40 @@ void CompletionModel::refresh(const QString &prefix, bool isFirstWord)
|
||||
// Twitch channel
|
||||
auto tc = dynamic_cast<TwitchChannel *>(&this->channel_);
|
||||
|
||||
std::function<void(const QString &str, TaggedString::Type type)> addString;
|
||||
if (getSettings()->prefixOnlyEmoteCompletion)
|
||||
{
|
||||
addString = [=](const QString &str, TaggedString::Type type) {
|
||||
if (str.startsWith(prefix, Qt::CaseInsensitive))
|
||||
this->items_.emplace(str + " ", type);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
addString = [=](const QString &str, TaggedString::Type type) {
|
||||
if (str.contains(prefix, Qt::CaseInsensitive))
|
||||
this->items_.emplace(str + " ", type);
|
||||
};
|
||||
}
|
||||
auto addString = [=](const QString &str, TaggedString::Type type) {
|
||||
// Special case for handling default Twitch commands
|
||||
if (type == TaggedString::TwitchCommand)
|
||||
{
|
||||
if (prefix.size() < 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto prefixChar = prefix.at(0);
|
||||
|
||||
static std::set<QChar> validPrefixChars{'/', '.'};
|
||||
|
||||
if (validPrefixChars.find(prefixChar) == validPrefixChars.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (startsWithOrContains((prefixChar + str), prefix,
|
||||
Qt::CaseInsensitive,
|
||||
getSettings()->prefixOnlyEmoteCompletion))
|
||||
{
|
||||
this->items_.emplace((prefixChar + str + " "), type);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (startsWithOrContains(str, prefix, Qt::CaseInsensitive,
|
||||
getSettings()->prefixOnlyEmoteCompletion))
|
||||
{
|
||||
this->items_.emplace(str + " ", type);
|
||||
}
|
||||
};
|
||||
|
||||
if (auto account = getApp()->accounts->twitch.getCurrent())
|
||||
{
|
||||
@@ -190,15 +210,22 @@ void CompletionModel::refresh(const QString &prefix, bool isFirstWord)
|
||||
addString(emote.first.string, TaggedString::Type::BTTVGlobalEmote);
|
||||
}
|
||||
|
||||
// Commands
|
||||
for (auto &command : getApp()->commands->items_)
|
||||
// Custom Chatterino commands
|
||||
for (auto &command : getApp()->commands->items)
|
||||
{
|
||||
addString(command.name, TaggedString::Command);
|
||||
addString(command.name, TaggedString::CustomCommand);
|
||||
}
|
||||
|
||||
for (auto &command : getApp()->commands->getDefaultTwitchCommandList())
|
||||
// Default Chatterino commands
|
||||
for (auto &command : getApp()->commands->getDefaultChatterinoCommandList())
|
||||
{
|
||||
addString(command, TaggedString::Command);
|
||||
addString(command, TaggedString::ChatterinoCommand);
|
||||
}
|
||||
|
||||
// Default Twitch commands
|
||||
for (auto &command : TWITCH_DEFAULT_COMMANDS)
|
||||
{
|
||||
addString(command, TaggedString::TwitchCommand);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user