Harden scrolling to bottom

Took 11 minutes
This commit is contained in:
Lukas Brübach 2026-08-08 20:38:15 +02:00
parent 15123ed0d2
commit 5da29fc52b
2 changed files with 17 additions and 1 deletions

View file

@ -13,6 +13,7 @@
#include <QDesktopServices> #include <QDesktopServices>
#include <QMouseEvent> #include <QMouseEvent>
#include <QScrollBar> #include <QScrollBar>
#include <QTimer>
#include <libcockatrice/network/server/remote/user_level.h> #include <libcockatrice/network/server/remote/user_level.h>
#include <libcockatrice/settings/chat_settings.h> #include <libcockatrice/settings/chat_settings.h>
@ -327,7 +328,20 @@ void ChatView::appendMessage(QString message,
} }
if (atBottom || messageType.testFlag(Event_RoomSay::ChatHistory)) { 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());
});
} }
} }

View file

@ -60,6 +60,7 @@ private:
QStringList highlightedWords; QStringList highlightedWords;
bool evenNumber; bool evenNumber;
bool showTimestamps; bool showTimestamps;
bool scrollToBottomPending = false;
HoveredItemType hoveredItemType; HoveredItemType hoveredItemType;
QString hoveredContent; QString hoveredContent;
QAction *messageClicked; QAction *messageClicked;
@ -67,6 +68,7 @@ private:
[[nodiscard]] QTextFragment getFragmentUnderMouse(const QPoint &pos) const; [[nodiscard]] QTextFragment getFragmentUnderMouse(const QPoint &pos) const;
QTextCursor prepareBlock(bool same = false); QTextCursor prepareBlock(bool same = false);
void scrollToBottom();
void appendCardTag(QTextCursor &cursor, const QString &cardName); void appendCardTag(QTextCursor &cursor, const QString &cardName);
void appendUrlTag(QTextCursor &cursor, QString url); void appendUrlTag(QTextCursor &cursor, QString url);
static QColor getCustomMentionColor(); static QColor getCustomMentionColor();