diff --git a/CHANGELOG.md b/CHANGELOG.md index 89c861131..d4c1a97a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unversioned +- Bugfix: Fixed message input showing as red after removing a message that was more than 500 characters. (#4204) - Bugfix: Fixed unnecessary saving of windows layout. (#4201) - Dev: Ignore `WM_SHOWWINDOW` hide events, causing fewer attempted rescales. (#4198) diff --git a/src/providers/twitch/TwitchCommon.hpp b/src/providers/twitch/TwitchCommon.hpp index 3882ee588..b80e12a03 100644 --- a/src/providers/twitch/TwitchCommon.hpp +++ b/src/providers/twitch/TwitchCommon.hpp @@ -15,6 +15,8 @@ namespace chatterino { static const char *ANONYMOUS_USERNAME ATTR_UNUSED = "justinfan64537"; +static constexpr int TWITCH_MESSAGE_LIMIT = 500; + inline QByteArray getDefaultClientID() { return QByteArray("7ue61iz46fz11y3cugd0l3tawb4taal"); diff --git a/src/widgets/splits/SplitInput.cpp b/src/widgets/splits/SplitInput.cpp index a1067a13d..f037520ca 100644 --- a/src/widgets/splits/SplitInput.cpp +++ b/src/widgets/splits/SplitInput.cpp @@ -6,6 +6,7 @@ #include "controllers/hotkeys/HotkeyController.hpp" #include "messages/Link.hpp" #include "providers/twitch/TwitchChannel.hpp" +#include "providers/twitch/TwitchCommon.hpp" #include "providers/twitch/TwitchIrcServer.hpp" #include "singletons/Settings.hpp" #include "singletons/Theme.hpp" @@ -25,6 +26,7 @@ #include #include +#include #include @@ -885,25 +887,29 @@ void SplitInput::editTextChanged() app->commands->execCommand(text, this->split_->getChannel(), true); } - if (getSettings()->messageOverflow.getValue() == MessageOverflow::Highlight) + if (text.length() > 0 && + getSettings()->messageOverflow.getValue() == MessageOverflow::Highlight) { - if (text.length() > TWITCH_MESSAGE_LIMIT && - text.length() > this->lastOverflowLength) - { - QTextCharFormat format; - format.setForeground(Qt::red); + QTextCursor cursor = this->ui_.textEdit->textCursor(); + QTextCharFormat format; + QList selections; - QTextCursor cursor = this->ui_.textEdit->textCursor(); - cursor.setPosition(lastOverflowLength, QTextCursor::MoveAnchor); + cursor.setPosition(qMin(text.length(), TWITCH_MESSAGE_LIMIT), + QTextCursor::MoveAnchor); + cursor.movePosition(QTextCursor::Start, QTextCursor::KeepAnchor); + selections.append({cursor, format}); + + if (text.length() > TWITCH_MESSAGE_LIMIT) + { + cursor.setPosition(TWITCH_MESSAGE_LIMIT, QTextCursor::MoveAnchor); cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor); - - this->lastOverflowLength = text.length(); - - cursor.setCharFormat(format); + format.setForeground(Qt::red); + selections.append({cursor, format}); } - else if (this->lastOverflowLength != TWITCH_MESSAGE_LIMIT) + // block reemit of QTextEdit::textChanged() { - this->lastOverflowLength = TWITCH_MESSAGE_LIMIT; + const QSignalBlocker b(this->ui_.textEdit); + this->ui_.textEdit->setExtraSelections(selections); } } diff --git a/src/widgets/splits/SplitInput.hpp b/src/widgets/splits/SplitInput.hpp index a118ce01f..18ae9cbe9 100644 --- a/src/widgets/splits/SplitInput.hpp +++ b/src/widgets/splits/SplitInput.hpp @@ -52,8 +52,6 @@ public: QString getInputText() const; void insertText(const QString &text); - static const int TWITCH_MESSAGE_LIMIT = 500; - void setReply(std::shared_ptr reply, bool showInlineReplying = true); void setPlaceholderText(const QString &text); @@ -151,8 +149,6 @@ protected: QString currMsg_; int prevIndex_ = 0; - int lastOverflowLength = TWITCH_MESSAGE_LIMIT; - // Hidden denotes whether this split input should be hidden or not // This is used instead of the regular QWidget::hide/show because // focus events don't work as expected, so instead we use this bool and