diff --git a/cockatrice/src/interface/widgets/server/chat_view/chat_view.cpp b/cockatrice/src/interface/widgets/server/chat_view/chat_view.cpp index b885fbe4b..64812b4a4 100644 --- a/cockatrice/src/interface/widgets/server/chat_view/chat_view.cpp +++ b/cockatrice/src/interface/widgets/server/chat_view/chat_view.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -327,7 +328,20 @@ void ChatView::appendMessage(QString message, } if (atBottom || messageType.testFlag(Event_RoomSay::ChatHistory)) { - verticalScrollBar()->setValue(verticalScrollBar()->maximum()); + scrollToBottom(); + } +} + +void ChatView::scrollToBottom() +{ + verticalScrollBar()->setValue(verticalScrollBar()->maximum()); + + if (!scrollToBottomPending) { + scrollToBottomPending = true; + QTimer::singleShot(0, this, [this] { + scrollToBottomPending = false; + verticalScrollBar()->setValue(verticalScrollBar()->maximum()); + }); } } diff --git a/cockatrice/src/interface/widgets/server/chat_view/chat_view.h b/cockatrice/src/interface/widgets/server/chat_view/chat_view.h index 506605d24..447bb33aa 100644 --- a/cockatrice/src/interface/widgets/server/chat_view/chat_view.h +++ b/cockatrice/src/interface/widgets/server/chat_view/chat_view.h @@ -60,6 +60,7 @@ private: QStringList highlightedWords; bool evenNumber; bool showTimestamps; + bool scrollToBottomPending = false; HoveredItemType hoveredItemType; QString hoveredContent; QAction *messageClicked; @@ -67,6 +68,7 @@ private: [[nodiscard]] QTextFragment getFragmentUnderMouse(const QPoint &pos) const; QTextCursor prepareBlock(bool same = false); + void scrollToBottom(); void appendCardTag(QTextCursor &cursor, const QString &cardName); void appendUrlTag(QTextCursor &cursor, QString url); static QColor getCustomMentionColor();