From b6d44bd94798e7eca23bfb98c9966f6f69c04c3b Mon Sep 17 00:00:00 2001 From: Evgeny Date: Fri, 24 Jul 2026 03:52:05 +0300 Subject: [PATCH] =?UTF-8?q?chatgui:=20don't=20save=20scroll=20position=20w?= =?UTF-8?q?hen=20at=20bottom=20=E2=80=94=20restore=20to=20bottom=20on=20re?= =?UTF-8?q?open?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When scrollbar is at max, save lastPosMsgId=0 so restoreScrollPosition falls through to scrollToBottom() instead of restoring a stale mid-scroll pos. --- tools/chatgui/src/messagelist.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/chatgui/src/messagelist.cpp b/tools/chatgui/src/messagelist.cpp index 57fc80da..d6f5de2f 100644 --- a/tools/chatgui/src/messagelist.cpp +++ b/tools/chatgui/src/messagelist.cpp @@ -288,9 +288,11 @@ void MessageList::saveChannelState() { int vpHeight = m_view->viewport()->height(); QModelIndex topIdx = m_view->indexAt(QPoint(0, 0)); + QScrollBar* sb = m_view->verticalScrollBar(); + bool atBottom = sb && (sb->value() >= sb->maximum()); qint64 lastPosMsgId = 0; - if (topIdx.isValid()) + if (!atBottom && topIdx.isValid()) lastPosMsgId = topIdx.data(MsgIdRole).toLongLong(); qint64 lastReadMsgId = m_lastReadMsgId; @@ -353,7 +355,9 @@ void MessageList::updateReadPosition() { } QModelIndex topIdx = m_view->indexAt(QPoint(0, 0)); - qint64 lastPosMsgId = topIdx.isValid() ? topIdx.data(MsgIdRole).toLongLong() : 0; + QScrollBar* sb = m_view->verticalScrollBar(); + bool atBottom = sb && (sb->value() >= sb->maximum()); + qint64 lastPosMsgId = (!atBottom && topIdx.isValid()) ? topIdx.data(MsgIdRole).toLongLong() : 0; DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "MessageList::updateReadPosition ch=%s oldRead=%lld newRead=%lld pos=%lld lastVisRow=%d/%d",