mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-31 10:41:08 +00:00
Merge bitcoin-core/gui#886: Avoid pathological QT text/markdown behavior...
6a371b70c87ad6b763c89384562fce8549f37434 gui: Avoid pathological QT text/markdown behavior... (David Gumberg) Pull request description: ...during text selection by only setting plaintext mime data. Fixes the OOM described in #887. The issue is related to the construction of the [`text/markdown`](b617d11765/src/widgets/widgets/qwidgettextcontrol.cpp (L3539)) MIME data for the selection. Using the `heaptrack` utility, I observed that nearly all of the allocations when reproducing happen in [`QTextMarkdownWriter::writeFrame`](b617d11765/src/gui/text/qtextmarkdownwriter.cpp (L95)). I am not 100% sure what is causing this issue in QT's conversion of our HTML to markdown; I have tried changing the [HTML tags](689a321976/src/qt/rpcconsole.cpp (L916-L924)) (e.g. using `<p></p`> and `<ul><li></li></ul>` in place of tables) used in our `rpcconsole` messages, but the issue recurs. The solution applied here is to override `createMimeDataFromSelection()` to avoid construction of the (likely never-used anyways) `text/markdown` mime data, and only set plaintext mime data in the clipboard. ACKs for top commit: hebasto: ACK 6a371b70c87ad6b763c89384562fce8549f37434. Tree-SHA512: 3edc4da47e6dbe939f27664d2265376938eed4f83ded3706e4b73677eac5c9a4ba8819f241428b45a08e8834982ee7759ee096afd090586db3b523d0ccbbbf73
This commit is contained in:
commit
ee42d59d4d
@ -573,7 +573,7 @@
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="messagesWidget">
|
||||
<widget class="PlainCopyTextEdit" name="messagesWidget">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
@ -1868,6 +1868,10 @@
|
||||
<slot>clear()</slot>
|
||||
</slots>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>PlainCopyTextEdit</class>
|
||||
<extends>QTextEdit</extends>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../bitcoin.qrc"/>
|
||||
|
||||
@ -15,6 +15,9 @@
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QCompleter>
|
||||
#include <QMimeData>
|
||||
#include <QTextDocumentFragment>
|
||||
#include <QTextEdit>
|
||||
#include <QThread>
|
||||
#include <QWidget>
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user