File tree 2 files changed +22
-3
lines changed
2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -534,9 +534,7 @@ GridLayout {
534
534
name: qsTr (" Copy" )
535
535
source: " qrc:/gpt4all/icons/copy.svg"
536
536
onClicked: {
537
- myTextArea .selectAll ();
538
- myTextArea .copy ();
539
- myTextArea .deselect ();
537
+ chatModel .copyToClipboard (index);
540
538
}
541
539
}
542
540
Original file line number Diff line number Diff line change 9
9
10
10
#include < fmt/format.h>
11
11
12
+ #include < QApplication>
12
13
#include < QAbstractListModel>
13
14
#include < QBuffer>
14
15
#include < QByteArray>
16
+ #include < QClipboard>
15
17
#include < QDataStream>
16
18
#include < QJsonDocument>
17
19
#include < QHash>
@@ -293,6 +295,15 @@ class ChatItem : public QObject
293
295
return code + result;
294
296
}
295
297
298
+ QString clipboardContent () const
299
+ {
300
+ QStringList clipContent;
301
+ for (const ChatItem *item : subItems)
302
+ clipContent << item->clipboardContent ();
303
+ clipContent << content ();
304
+ return clipContent.join (" " );
305
+ }
306
+
296
307
QList<ChatItem *> childItems () const
297
308
{
298
309
// We currently have leaf nodes at depth 3 with nodes at depth 2 as mere containers we don't
@@ -971,6 +982,16 @@ class ChatModel : public QAbstractListModel
971
982
emit hasErrorChanged (value);
972
983
}
973
984
985
+ Q_INVOKABLE void copyToClipboard (int index)
986
+ {
987
+ QMutexLocker locker (&m_mutex);
988
+ if (index < 0 || index >= m_chatItems.size ())
989
+ return ;
990
+ ChatItem *item = m_chatItems.at (index );
991
+ QClipboard *clipboard = QGuiApplication::clipboard ();
992
+ clipboard->setText (item->clipboardContent (), QClipboard::Clipboard);
993
+ }
994
+
974
995
qsizetype count () const { QMutexLocker locker (&m_mutex); return m_chatItems.size (); }
975
996
976
997
std::vector<MessageItem> messageItems () const
You can’t perform that action at this time.
0 commit comments