Skip to content

Commit 62bdefb

Browse files
committed
Scroll to bottom after adding follow‑up widget
When a follow‑up widget was appended to the message layout the view did not automatically scroll to the new content. The change now calls `scrollToBottom()` from `createFollowUpWidget` and defers the actual scroll action with `QTimer::singleShot(100)`. This gives the layout time to finish rendering before the scrollbar is updated, ensuring the latest message is visible immediately and eliminating jitter when the editor is first opened or after a rapid series of messages. Also updated the implementation of `scrollToBottom()` to use the timer instead of setting the scrollbar value directly.
1 parent d7c0230 commit 62bdefb

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

llamachateditor.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ void ChatEditor::createFollowUpWidget(const QString &convId,
273273
lay->addStretch();
274274
// Append below the regular messages
275275
m_messageLayout->addWidget(m_followUpWidget);
276+
277+
scrollToBottom();
276278
}
277279

278280
void ChatEditor::refreshMessages(const QVector<Message> &messages, qint64 leafNodeId)
@@ -512,8 +514,11 @@ void ChatEditor::updateSpeedLabel(const Message &msg)
512514

513515
void ChatEditor::scrollToBottom()
514516
{
515-
QScrollBar *sb = m_scrollArea->verticalScrollBar();
516-
sb->setValue(sb->maximum());
517+
// Scroll to bottom after the layout has finished
518+
QTimer::singleShot(100, this, [this] {
519+
QScrollBar *sb = m_scrollArea->verticalScrollBar();
520+
sb->setValue(sb->maximum());
521+
});
517522
}
518523

519524
class ChatEditorFactory final : public IEditorFactory

0 commit comments

Comments
 (0)