From b513caf572f9b84fbc9fe2a267c6ab4e555f874f Mon Sep 17 00:00:00 2001 From: fourtf Date: Wed, 21 Aug 2019 01:08:15 +0200 Subject: [PATCH] added settings to mention users with , --- src/common/CompletionModel.cpp | 11 ++++++++--- src/common/CompletionModel.hpp | 2 +- src/singletons/Settings.hpp | 2 ++ src/widgets/helper/ResizingTextEdit.cpp | 13 ++++++++++++- src/widgets/settingspages/GeneralPage.cpp | 2 ++ 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/common/CompletionModel.cpp b/src/common/CompletionModel.cpp index 7d9251bc..9bac550d 100644 --- a/src/common/CompletionModel.cpp +++ b/src/common/CompletionModel.cpp @@ -77,7 +77,7 @@ int CompletionModel::rowCount(const QModelIndex &) const return this->items_.size(); } -void CompletionModel::refresh(const QString &prefix) +void CompletionModel::refresh(const QString &prefix, bool isFirstWord) { std::function addString; if (getSettings()->prefixOnlyEmoteCompletion) @@ -120,6 +120,9 @@ void CompletionModel::refresh(const QString &prefix) auto usernames = channel->accessChatters(); QString usernamePrefix = prefix; + QString usernamePostfix = + isFirstWord && getSettings()->mentionUsersWithComma ? "," + : QString(); if (usernamePrefix.startsWith("@")) { @@ -127,7 +130,8 @@ void CompletionModel::refresh(const QString &prefix) for (const auto &name : usernames->subrange(Prefix(usernamePrefix))) { - addString("@" + name, TaggedString::Type::Username); + addString("@" + name + usernamePostfix, + TaggedString::Type::Username); } } else @@ -135,7 +139,8 @@ void CompletionModel::refresh(const QString &prefix) for (const auto &name : usernames->subrange(Prefix(usernamePrefix))) { - addString(name, TaggedString::Type::Username); + addString(name + usernamePostfix, + TaggedString::Type::Username); } } } diff --git a/src/common/CompletionModel.hpp b/src/common/CompletionModel.hpp index f4f216cd..d33fcaed 100644 --- a/src/common/CompletionModel.hpp +++ b/src/common/CompletionModel.hpp @@ -47,7 +47,7 @@ public: virtual QVariant data(const QModelIndex &index, int) const override; virtual int rowCount(const QModelIndex &) const override; - void refresh(const QString &prefix); + void refresh(const QString &prefix, bool isFirstWord = false); private: TaggedString createUser(const QString &str); diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index 4f6e04dc..295ad7e5 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -104,6 +104,8 @@ public: BoolSetting pauseChatOnHover = {"/behaviour/pauseChatHover", false}; BoolSetting autorun = {"/behaviour/autorun", false}; + BoolSetting mentionUsersWithComma = {"/behaviour/mentionUsersWithComma", + true}; /// Commands BoolSetting allowCommandsAtEnd = {"/commands/allowCommandsAtEnd", false}; diff --git a/src/widgets/helper/ResizingTextEdit.cpp b/src/widgets/helper/ResizingTextEdit.cpp index cee49139..edaa1173 100644 --- a/src/widgets/helper/ResizingTextEdit.cpp +++ b/src/widgets/helper/ResizingTextEdit.cpp @@ -102,6 +102,17 @@ void ResizingTextEdit::keyPressEvent(QKeyEvent *event) } QString currentCompletionPrefix = this->textUnderCursor(); + bool isFirstWord = [&] { + QString plainText = this->toPlainText(); + for (int i = this->textCursor().position(); i >= 0; i--) + { + if (plainText[i] == ' ') + { + return false; + } + } + return true; + }(); // check if there is something to complete if (currentCompletionPrefix.size() <= 1) @@ -117,7 +128,7 @@ void ResizingTextEdit::keyPressEvent(QKeyEvent *event) // First type pressing tab after modifying a message, we refresh our // completion model this->completer_->setModel(completionModel); - completionModel->refresh(currentCompletionPrefix); + completionModel->refresh(currentCompletionPrefix, isFirstWord); this->completionInProgress_ = true; this->completer_->setCompletionPrefix(currentCompletionPrefix); this->completer_->complete(); diff --git a/src/widgets/settingspages/GeneralPage.cpp b/src/widgets/settingspages/GeneralPage.cpp index 28b71728..443e00d8 100644 --- a/src/widgets/settingspages/GeneralPage.cpp +++ b/src/widgets/settingspages/GeneralPage.cpp @@ -262,6 +262,8 @@ void GeneralPage::initLayout(SettingsLayout &layout) layout.addCheckbox("Show stream title", s.headerStreamTitle); layout.addTitle("Miscellaneous"); + layout.addCheckbox("Mention users with a comma (User,)", + s.mentionUsersWithComma); layout.addCheckbox("Show joined users (< 1000 chatters)", s.showJoins); layout.addCheckbox("Show parted users (< 1000 chatters)", s.showParts); layout.addCheckbox("Lowercase domains", s.lowercaseDomains);