Fix chat rendering and improve scroll behavior
- Emit SegmentsRole in dataChanged signals so QML updates properly - Add onContentHeightChanged to scroll when content loads after session switch - Add floating scroll-to-bottom button that appears when scrolled up - Wrap chat ScrollView in Item to allow button overlay
This commit is contained in:
parent
07232b94df
commit
0ac03a9931
|
|
@ -223,7 +223,7 @@ void ChatBlockModel::appendData(const QString &text)
|
|||
|
||||
// But emit with the rendered HTML that includes partial content
|
||||
QModelIndex idx = index(m_blocks.size() - 1);
|
||||
emit dataChanged(idx, idx, {RenderedHtmlRole});
|
||||
emit dataChanged(idx, idx, {RenderedHtmlRole, SegmentsRole});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -483,7 +483,7 @@ void ChatBlockModel::appendContent(const QString &line)
|
|||
rebuildBlockHtml(m_blocks.size() - 1);
|
||||
|
||||
QModelIndex idx = index(m_blocks.size() - 1);
|
||||
emit dataChanged(idx, idx, {ContentRole, RenderedHtmlRole});
|
||||
emit dataChanged(idx, idx, {ContentRole, RenderedHtmlRole, SegmentsRole});
|
||||
}
|
||||
|
||||
void ChatBlockModel::processLine(const QString &line)
|
||||
|
|
|
|||
46
gui/main.qml
46
gui/main.qml
|
|
@ -1220,10 +1220,13 @@ ApplicationWindow {
|
|||
|
||||
Rectangle { Layout.fillWidth: true; height: 1; color: theme.midColor }
|
||||
|
||||
// Chat display — block-based ListView
|
||||
ScrollView {
|
||||
// Chat display — block-based ListView with scroll-to-bottom button
|
||||
Item {
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
|
||||
ScrollView {
|
||||
anchors.fill: parent
|
||||
clip: true
|
||||
|
||||
// Placeholder when no agent selected or disconnected
|
||||
|
|
@ -1262,6 +1265,13 @@ ApplicationWindow {
|
|||
}
|
||||
}
|
||||
|
||||
onContentHeightChanged: {
|
||||
// Content height changed (e.g., after loading) - scroll if following
|
||||
if (shouldAutoScroll && count > 0) {
|
||||
positionViewAtEnd()
|
||||
}
|
||||
}
|
||||
|
||||
onCountChanged: {
|
||||
// New block added - always scroll if we were following
|
||||
if (count > 0) {
|
||||
|
|
@ -1587,6 +1597,38 @@ property bool blockExpanded: {
|
|||
}
|
||||
}
|
||||
|
||||
// Scroll-to-bottom floating button
|
||||
Rectangle {
|
||||
id: scrollToBottomBtn
|
||||
width: 40
|
||||
height: 40
|
||||
radius: 20
|
||||
color: theme.highlightColor
|
||||
opacity: 0.9
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.margins: 16
|
||||
visible: !chatView.shouldAutoScroll && chatView.count > 0 && chatView.visible
|
||||
|
||||
Label {
|
||||
anchors.centerIn: parent
|
||||
text: "↓"
|
||||
font.pixelSize: 20
|
||||
font.bold: true
|
||||
color: theme.highlightedTextColor
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: {
|
||||
chatView.shouldAutoScroll = true
|
||||
chatView.positionViewAtEnd()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle { Layout.fillWidth: true; height: 1; color: theme.midColor }
|
||||
|
||||
// Input
|
||||
|
|
|
|||
Reference in New Issue