feat(spellchecking): ignore commands for spellchecking (#6731)
This commit is contained in:
+1
-1
@@ -78,7 +78,7 @@
|
|||||||
- Dev: Unwrapped `LimitedQueueSnapshot` to `std::vector`. (#6606)
|
- Dev: Unwrapped `LimitedQueueSnapshot` to `std::vector`. (#6606)
|
||||||
- Dev: Simplified uses of `getMessageSnapshot`. (#6607)
|
- Dev: Simplified uses of `getMessageSnapshot`. (#6607)
|
||||||
- Dev: Disabled `llvm-prefer-static-over-anonymous-namespace` in clang-tidy. (#6610)
|
- Dev: Disabled `llvm-prefer-static-over-anonymous-namespace` in clang-tidy. (#6610)
|
||||||
- Dev: Added experimental spell checker support. (#6446, #6703, #6722, #6730)
|
- Dev: Added experimental spell checker support. (#6446, #6703, #6722, #6730, #6731)
|
||||||
- Dev: Added Clazy linting in CI. (#6623)
|
- Dev: Added Clazy linting in CI. (#6623)
|
||||||
- Dev: Added custom clang-tidy module linting in CI. (#6626)
|
- Dev: Added custom clang-tidy module linting in CI. (#6626)
|
||||||
- Dev: CMake option `USE_ALTERNATE_LINKER` now errors if the given linker can't be found. (#6692)
|
- Dev: CMake option `USE_ALTERNATE_LINKER` now errors if the given linker can't be found. (#6692)
|
||||||
|
|||||||
@@ -733,4 +733,36 @@ QStringList CommandController::getDefaultChatterinoCommandList()
|
|||||||
return this->defaultChatterinoCommandAutoCompletions_;
|
return this->defaultChatterinoCommandAutoCompletions_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qsizetype CommandController::commandTriggerLen(QStringView text)
|
||||||
|
{
|
||||||
|
auto words = text.split(' ');
|
||||||
|
|
||||||
|
qsizetype triggerLen = 0;
|
||||||
|
qsizetype spaces = 0;
|
||||||
|
QString commandName{};
|
||||||
|
|
||||||
|
for (qsizetype i = 0; i < words.length() && spaces <= this->maxSpaces_; ++i)
|
||||||
|
{
|
||||||
|
commandName += words[i];
|
||||||
|
triggerLen += words[i].length();
|
||||||
|
|
||||||
|
if (this->commands_.contains(commandName) ||
|
||||||
|
this->userCommands_.contains(commandName))
|
||||||
|
{
|
||||||
|
return triggerLen;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ignore consecutive spaces
|
||||||
|
if (!words[i].isEmpty())
|
||||||
|
{
|
||||||
|
commandName += ' ';
|
||||||
|
++spaces;
|
||||||
|
}
|
||||||
|
// account for the space between the current and next word
|
||||||
|
++triggerLen;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|||||||
@@ -55,6 +55,13 @@ public:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/// Returns the length of the command trigger in `text`, including leading
|
||||||
|
/// spaces. If `text` does not start with a command trigger, 0 is returned.
|
||||||
|
/// Examples:
|
||||||
|
/// - " /ban forsen" returns 5
|
||||||
|
/// - "/non-existing-command" returns 0
|
||||||
|
qsizetype commandTriggerLen(QStringView text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void load(Paths &paths);
|
void load(Paths &paths);
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "common/Aliases.hpp"
|
#include "common/Aliases.hpp"
|
||||||
#include "common/LinkParser.hpp"
|
#include "common/LinkParser.hpp"
|
||||||
#include "controllers/accounts/AccountController.hpp"
|
#include "controllers/accounts/AccountController.hpp"
|
||||||
|
#include "controllers/commands/CommandController.hpp"
|
||||||
#include "controllers/spellcheck/SpellChecker.hpp"
|
#include "controllers/spellcheck/SpellChecker.hpp"
|
||||||
#include "messages/Emote.hpp"
|
#include "messages/Emote.hpp"
|
||||||
#include "providers/bttv/BttvEmotes.hpp"
|
#include "providers/bttv/BttvEmotes.hpp"
|
||||||
@@ -96,19 +97,26 @@ void InputHighlighter::highlightBlock(const QString &text)
|
|||||||
auto *channel = this->channel.lock().get();
|
auto *channel = this->channel.lock().get();
|
||||||
|
|
||||||
QStringView textView = text;
|
QStringView textView = text;
|
||||||
|
|
||||||
|
// skip leading command trigger
|
||||||
|
auto cmdTriggerLen = getApp()->getCommands()->commandTriggerLen(textView);
|
||||||
|
textView = textView.sliced(cmdTriggerLen);
|
||||||
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
|
||||||
auto it = this->wordRegex.globalMatchView(textView);
|
auto it = this->wordRegex.globalMatchView(textView);
|
||||||
#else
|
#else
|
||||||
auto it = this->wordRegex.globalMatch(textView);
|
auto it = this->wordRegex.globalMatch(textView);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
auto match = it.next();
|
auto match = it.next();
|
||||||
auto text = match.captured();
|
auto text = match.captured();
|
||||||
if (!isIgnoredWord(channel, text) && !this->spellChecker.check(text))
|
if (!isIgnoredWord(channel, text) && !this->spellChecker.check(text))
|
||||||
{
|
{
|
||||||
this->setFormat(static_cast<int>(match.capturedStart()),
|
this->setFormat(
|
||||||
static_cast<int>(text.size()), this->spellFmt);
|
static_cast<int>(match.capturedStart() + cmdTriggerLen),
|
||||||
|
static_cast<int>(text.size()), this->spellFmt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user