Make Emote Tab Completion Search for Substrings (#1204)

* Make emote tab completion search for substrings

Previously, tab completion only searched for emotes that start
with the current prefix under the cursor. This commit makes tab
completion look for the current prefix as a substring in any position,
not just the start.

Examples:
    * In forsen's channel, tabbing on "pls" will cycle through "DonaldPls", "forsenPls",
    "GachiPls", "nyanPls" and "SourPls".

    * As a forsen subscriber, tabbing on "sen1" will complete to "forsen1".

    * As a pajlada subscriber, tabbing on "shrug" will cycle through
    "pajaShrugL" and "pajaShrugR". (Unless you are in a channel with
    more "shrug" emotes, of course.)

* Add a setting for prefix and substring completion

This commit adds a setting under the "Miscellaneous" section to allow
user to choose whether they want prefix-only or substring emote
completion.

The QCompleter filter mode and `addString` function are now chosen
according to the user's setting.

* Improve description of emote completion setting

Also reintroduce a blank line that went missing.
This commit is contained in:
Leon Richardt
2019-08-17 17:17:38 +02:00
committed by fourtf
parent 3dcbe89e28
commit 58d892a8c2
4 changed files with 31 additions and 5 deletions
+11
View File
@@ -1,6 +1,7 @@
#include "widgets/helper/ResizingTextEdit.hpp"
#include "common/Common.hpp"
#include "common/CompletionModel.hpp"
#include "singletons/Settings.hpp"
namespace chatterino {
@@ -198,6 +199,16 @@ void ResizingTextEdit::setCompleter(QCompleter *c)
this->completer_->setWidget(this);
this->completer_->setCompletionMode(QCompleter::InlineCompletion);
this->completer_->setCaseSensitivity(Qt::CaseInsensitive);
if (getSettings()->prefixOnlyEmoteCompletion)
{
this->completer_->setFilterMode(Qt::MatchStartsWith);
}
else
{
this->completer_->setFilterMode(Qt::MatchContains);
}
QObject::connect(completer_,
static_cast<void (QCompleter::*)(const QString &)>(
&QCompleter::highlighted),