Browse Source

chatgui: don't save scroll position when at bottom — restore to bottom on reopen

When scrollbar is at max, save lastPosMsgId=0 so restoreScrollPosition
falls through to scrollToBottom() instead of restoring a stale mid-scroll pos.
topo_upd
Evgeny 2 months ago
parent
commit
b6d44bd947
  1. 8
      tools/chatgui/src/messagelist.cpp

8
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",

Loading…
Cancel
Save