fix: "reply to message" now takes usernames with @'s & commas into consideration (#5173)

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
Co-authored-by: Felanbird <41973452+Felanbird@users.noreply.github.com>
This commit is contained in:
KleberPF
2024-02-17 10:25:14 -03:00
committed by GitHub
parent 32d269dffc
commit 42e4559910
3 changed files with 93 additions and 14 deletions
+22 -6
View File
@@ -1113,16 +1113,32 @@ void SplitInput::setReply(MessagePtr reply, bool showReplyingLabel)
// Only enable reply label if inline replying
auto replyPrefix = "@" + this->replyThread_->displayName;
auto plainText = this->ui_.textEdit->toPlainText().trimmed();
if (!plainText.startsWith(replyPrefix))
// This makes it so if plainText contains "@StreamerFan" and
// we are replying to "@Streamer" we don't just leave "Fan"
// in the text box
if (plainText.startsWith(replyPrefix))
{
if (!plainText.isEmpty())
if (plainText.length() > replyPrefix.length())
{
replyPrefix.append(' ');
if (plainText.at(replyPrefix.length()) == ',' ||
plainText.at(replyPrefix.length()) == ' ')
{
plainText.remove(0, replyPrefix.length() + 1);
}
}
else
{
plainText.remove(0, replyPrefix.length());
}
this->ui_.textEdit->setPlainText(replyPrefix + plainText + " ");
this->ui_.textEdit->moveCursor(QTextCursor::EndOfBlock);
this->ui_.textEdit->resetCompletion();
}
if (!plainText.isEmpty() && !plainText.startsWith(' '))
{
replyPrefix.append(' ');
}
this->ui_.textEdit->setPlainText(replyPrefix + plainText + " ");
this->ui_.textEdit->moveCursor(QTextCursor::EndOfBlock);
this->ui_.textEdit->resetCompletion();
this->ui_.replyLabel->setText("Replying to @" +
this->replyThread_->displayName);
}