diff --git a/gui/ChatPane.qml b/gui/ChatPane.qml index 2a4524b..e281ca7 100644 --- a/gui/ChatPane.qml +++ b/gui/ChatPane.qml @@ -5,15 +5,23 @@ import QtQuick.Layouts 1.15 Item { id: chatPane property bool sidebarVisible: true + property int maxVisibleBlocks: 80 signal toggleSidebar() function scrollToBottom() { chatView.positionViewAtEnd() } + function trimVisibleBlocks() { + if (chatModel.count > chatPane.maxVisibleBlocks) + chatModel.trimFront(chatPane.maxVisibleBlocks) + } function loadChat() { chatModel.reset() if (ollie.activeSessionId && ollie.activeAgentId) { var log = ollie.readLogForSession(ollie.activeSessionId, ollie.activeAgentId) - if (log) { chatModel.appendData(log); chatModel.trimFront(20) } + if (log) { + chatModel.appendData(log) + chatModel.trimFront(chatPane.maxVisibleBlocks) + } } scrollToBottom() } @@ -124,6 +132,13 @@ Item { anchors.margins: 4 visible: ollie.daemonConnected && ollie.activeAgentId !== "" + onCountChanged: { + if (!scrollButton.visible) chatPane.scrollToBottom() + } + onContentHeightChanged: { + if (!scrollButton.visible) chatPane.scrollToBottom() + } + delegate: ChatBlockDelegate { width: chatView.width - 8 } @@ -167,7 +182,8 @@ Item { } } Button { - anchors.right: parent.right + id: scrollButton + anchors.horizontalCenter: parent.horizontalCenter anchors.bottom: parent.bottom anchors.margins: 12 text: "↓" @@ -272,6 +288,11 @@ Item { } +Connections { + target: chatModel + function onCountChanged() { chatPane.trimVisibleBlocks() } +} + Connections { target: ollie function onSessionsChanged() { chatPane.loadChat() }