mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-05-28 03:10:28 -04:00
feat: Add reset button to clean message list to specific message (#168)
This commit is contained in:
parent
711aa672f2
commit
7a33425d1a
@ -197,4 +197,16 @@ QString ChatModel::lastMessageId() const
|
|||||||
return !m_messages.isEmpty() ? m_messages.last().id : "";
|
return !m_messages.isEmpty() ? m_messages.last().id : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChatModel::resetModelTo(int index)
|
||||||
|
{
|
||||||
|
if (index < 0 || index >= m_messages.size())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (index < m_messages.size() - 1) {
|
||||||
|
beginRemoveRows(QModelIndex(), index, m_messages.size() - 1);
|
||||||
|
m_messages.remove(index, m_messages.size() - index);
|
||||||
|
endRemoveRows();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace QodeAssist::Chat
|
} // namespace QodeAssist::Chat
|
||||||
|
@ -73,6 +73,8 @@ public:
|
|||||||
QString currentModel() const;
|
QString currentModel() const;
|
||||||
QString lastMessageId() const;
|
QString lastMessageId() const;
|
||||||
|
|
||||||
|
Q_INVOKABLE void resetModelTo(int index);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void tokensThresholdChanged();
|
void tokensThresholdChanged();
|
||||||
void modelReseted();
|
void modelReseted();
|
||||||
|
@ -28,12 +28,19 @@ Rectangle {
|
|||||||
property alias msgModel: msgCreator.model
|
property alias msgModel: msgCreator.model
|
||||||
property alias messageAttachments: attachmentsModel.model
|
property alias messageAttachments: attachmentsModel.model
|
||||||
property bool isUserMessage: false
|
property bool isUserMessage: false
|
||||||
|
property int messageIndex: -1
|
||||||
|
|
||||||
|
signal resetChatToMessage(int index)
|
||||||
|
|
||||||
height: msgColumn.implicitHeight + 10
|
height: msgColumn.implicitHeight + 10
|
||||||
radius: 8
|
radius: 8
|
||||||
color: isUserMessage ? palette.alternateBase
|
color: isUserMessage ? palette.alternateBase
|
||||||
: palette.base
|
: palette.base
|
||||||
|
|
||||||
|
HoverHandler {
|
||||||
|
id: mouse
|
||||||
|
}
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
id: msgColumn
|
id: msgColumn
|
||||||
|
|
||||||
@ -128,6 +135,22 @@ Rectangle {
|
|||||||
visible: root.isUserMessage
|
visible: root.isUserMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QoAButton {
|
||||||
|
id: stopButtonId
|
||||||
|
|
||||||
|
anchors {
|
||||||
|
right: parent.right
|
||||||
|
bottom: parent.bottom
|
||||||
|
bottomMargin: 2
|
||||||
|
}
|
||||||
|
|
||||||
|
text: qsTr("ResetTo")
|
||||||
|
visible: root.isUserMessage && mouse.hovered
|
||||||
|
onClicked: function() {
|
||||||
|
root.resetChatToMessage(root.messageIndex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
component TextComponent : TextBlock {
|
component TextComponent : TextBlock {
|
||||||
required property var itemData
|
required property var itemData
|
||||||
height: implicitHeight + 10
|
height: implicitHeight + 10
|
||||||
|
@ -92,11 +92,19 @@ ChatRootView {
|
|||||||
|
|
||||||
delegate: ChatItem {
|
delegate: ChatItem {
|
||||||
required property var model
|
required property var model
|
||||||
|
required property int index
|
||||||
|
|
||||||
width: ListView.view.width - scroll.width
|
width: ListView.view.width - scroll.width
|
||||||
msgModel: root.chatModel.processMessageContent(model.content)
|
msgModel: root.chatModel.processMessageContent(model.content)
|
||||||
messageAttachments: model.attachments
|
messageAttachments: model.attachments
|
||||||
isUserMessage: model.roleType === ChatModel.User
|
isUserMessage: model.roleType === ChatModel.User
|
||||||
|
messageIndex: index
|
||||||
|
|
||||||
|
onResetChatToMessage: function(index) {
|
||||||
|
messageInput.text = model.content
|
||||||
|
messageInput.cursorPosition = model.content.length
|
||||||
|
root.chatModel.resetModelTo(index)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
header: Item {
|
header: Item {
|
||||||
|
Loading…
Reference in New Issue
Block a user