From 6b19ede1a5b500d66e8edaef6e8d80492ed9f74f Mon Sep 17 00:00:00 2001 From: David Gumberg Date: Wed, 3 Sep 2025 16:00:31 -0700 Subject: [PATCH] gui: Avoid pathological QT text/markdown behavior... during text selection by only setting plaintext mime data. Github-Pull: https://github.com/bitcoin-core/gui/pull/886 Rebased-From: 6a371b70c87ad6b763c89384562fce8549f37434 --- src/qt/forms/debugwindow.ui | 6 +++++- src/qt/rpcconsole.h | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/qt/forms/debugwindow.ui b/src/qt/forms/debugwindow.ui index eccea143189..d1c627bb3ce 100644 --- a/src/qt/forms/debugwindow.ui +++ b/src/qt/forms/debugwindow.ui @@ -573,7 +573,7 @@ - + 0 @@ -1868,6 +1868,10 @@ clear() + + PlainCopyTextEdit + QTextEdit + diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h index a1b9522b98e..fe2955cc26b 100644 --- a/src/qt/rpcconsole.h +++ b/src/qt/rpcconsole.h @@ -15,6 +15,9 @@ #include #include +#include +#include +#include #include #include @@ -191,4 +194,20 @@ private Q_SLOTS: void updateAlerts(const QString& warnings); }; +/** + * A version of QTextEdit that only populates plaintext mime data from a + * selection, this avoids some bad behavior in QT's HTML->Markdown conversion. + */ +class PlainCopyTextEdit : public QTextEdit { + Q_OBJECT +public: + using QTextEdit::QTextEdit; +protected: + QMimeData* createMimeDataFromSelection() const override { + auto md = new QMimeData(); + md->setText(textCursor().selection().toPlainText()); + return md; + } +}; + #endif // BITCOIN_QT_RPCCONSOLE_H