Fixed comma appended to username completion when not at the beginning of the message (#3060)
Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
#include "singletons/WindowManager.hpp"
|
||||
#include "util/Clipboard.hpp"
|
||||
#include "util/DistanceBetweenPoints.hpp"
|
||||
#include "util/Helpers.hpp"
|
||||
#include "util/IncognitoBrowser.hpp"
|
||||
#include "util/StreamerMode.hpp"
|
||||
#include "util/Twitch.hpp"
|
||||
@@ -48,6 +49,7 @@
|
||||
#include "widgets/helper/EffectLabel.hpp"
|
||||
#include "widgets/helper/SearchPopup.hpp"
|
||||
#include "widgets/splits/Split.hpp"
|
||||
#include "widgets/splits/SplitInput.hpp"
|
||||
|
||||
#define DRAW_WIDTH (this->width())
|
||||
#define SELECTION_RESUME_SCROLLING_MSG_THRESHOLD 3
|
||||
@@ -1804,8 +1806,9 @@ void ChannelView::handleMouseClick(QMouseEvent *event,
|
||||
}
|
||||
break;
|
||||
case Qt::RightButton: {
|
||||
auto split = dynamic_cast<Split *>(this->parentWidget());
|
||||
auto insertText = [=](QString text) {
|
||||
if (auto split = dynamic_cast<Split *>(this->parentWidget()))
|
||||
if (split)
|
||||
{
|
||||
split->insertTextToInput(text);
|
||||
}
|
||||
@@ -1815,7 +1818,11 @@ void ChannelView::handleMouseClick(QMouseEvent *event,
|
||||
if (link.type == Link::UserInfo)
|
||||
{
|
||||
const bool commaMention = getSettings()->mentionUsersWithComma;
|
||||
insertText("@" + link.value + (commaMention ? ", " : " "));
|
||||
const bool isFirstWord =
|
||||
split && split->getInput().isEditFirstWord();
|
||||
auto userMention =
|
||||
formatUserMention(link.value, isFirstWord, commaMention);
|
||||
insertText("@" + userMention + " ");
|
||||
}
|
||||
else if (link.type == Link::UserWhisper)
|
||||
{
|
||||
|
||||
@@ -39,6 +39,19 @@ bool ResizingTextEdit::hasHeightForWidth() const
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ResizingTextEdit::isFirstWord() const
|
||||
{
|
||||
QString plainText = this->toPlainText();
|
||||
for (int i = this->textCursor().position(); i >= 0; i--)
|
||||
{
|
||||
if (plainText[i] == ' ')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
int ResizingTextEdit::heightForWidth(int) const
|
||||
{
|
||||
auto margins = this->contentsMargins();
|
||||
@@ -108,17 +121,6 @@ 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)
|
||||
@@ -134,7 +136,8 @@ 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, isFirstWord);
|
||||
completionModel->refresh(currentCompletionPrefix,
|
||||
this->isFirstWord());
|
||||
this->completionInProgress_ = true;
|
||||
this->completer_->setCompletionPrefix(currentCompletionPrefix);
|
||||
this->completer_->complete();
|
||||
|
||||
@@ -15,6 +15,7 @@ public:
|
||||
QSize sizeHint() const override;
|
||||
|
||||
bool hasHeightForWidth() const override;
|
||||
bool isFirstWord() const;
|
||||
|
||||
pajlada::Signals::Signal<QKeyEvent *> keyPressed;
|
||||
pajlada::Signals::NoArgSignal focused;
|
||||
|
||||
@@ -306,6 +306,11 @@ ChannelView &Split::getChannelView()
|
||||
return *this->view_;
|
||||
}
|
||||
|
||||
SplitInput &Split::getInput()
|
||||
{
|
||||
return *this->input_;
|
||||
}
|
||||
|
||||
void Split::updateInputPlaceholder()
|
||||
{
|
||||
if (!this->getChannel()->isTwitchChannel())
|
||||
|
||||
@@ -47,6 +47,7 @@ public:
|
||||
pajlada::Signals::NoArgSignal focusLost;
|
||||
|
||||
ChannelView &getChannelView();
|
||||
SplitInput &getInput();
|
||||
|
||||
IndirectChannel getIndirectChannel();
|
||||
ChannelPtr getChannel();
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "singletons/Theme.hpp"
|
||||
#include "util/Clamp.hpp"
|
||||
#include "util/Helpers.hpp"
|
||||
#include "util/LayoutCreator.hpp"
|
||||
#include "widgets/Notebook.hpp"
|
||||
#include "widgets/Scrollbar.hpp"
|
||||
@@ -568,8 +569,10 @@ void SplitInput::insertCompletionText(const QString &input_)
|
||||
}
|
||||
else if (text[i] == '@')
|
||||
{
|
||||
input = "@" + input_ +
|
||||
(getSettings()->mentionUsersWithComma ? ", " : " ");
|
||||
const auto userMention =
|
||||
formatUserMention(input_, edit.isFirstWord(),
|
||||
getSettings()->mentionUsersWithComma);
|
||||
input = "@" + userMention + " ";
|
||||
done = true;
|
||||
}
|
||||
|
||||
@@ -595,6 +598,11 @@ void SplitInput::clearSelection()
|
||||
this->ui_.textEdit->setTextCursor(c);
|
||||
}
|
||||
|
||||
bool SplitInput::isEditFirstWord() const
|
||||
{
|
||||
return this->ui_.textEdit->isFirstWord();
|
||||
}
|
||||
|
||||
QString SplitInput::getInputText() const
|
||||
{
|
||||
return this->ui_.textEdit->toPlainText();
|
||||
|
||||
@@ -28,6 +28,7 @@ public:
|
||||
SplitInput(Split *_chatWidget);
|
||||
|
||||
void clearSelection();
|
||||
bool isEditFirstWord() const;
|
||||
QString getInputText() const;
|
||||
void insertText(const QString &text);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user