forked from qt-creator/qt-creator
Utils: Remove ObjectReplacementChars when copying from markdownbrowser
Change-Id: I9ab8a2995eff866a13a5dbe269a53dcfb4dfeec2 Reviewed-by: <lie@spyro-soft.com> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -29,6 +29,8 @@
|
|||||||
#include <QTextBlock>
|
#include <QTextBlock>
|
||||||
#include <QTextBrowser>
|
#include <QTextBrowser>
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
|
#include <QTextDocumentFragment>
|
||||||
|
#include <QTextDocumentWriter>
|
||||||
#include <QTextObjectInterface>
|
#include <QTextObjectInterface>
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
@@ -862,6 +864,31 @@ void MarkdownBrowser::mousePressEvent(QMouseEvent *event)
|
|||||||
QTextBrowser::mousePressEvent(event);
|
QTextBrowser::mousePressEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QMimeData *MarkdownBrowser::createMimeDataFromSelection() const
|
||||||
|
{
|
||||||
|
// Basically a copy of QTextEditMimeData::setup, just replacing the object markers.
|
||||||
|
QMimeData *mimeData = new QMimeData;
|
||||||
|
QTextDocumentFragment fragment(textCursor());
|
||||||
|
|
||||||
|
static const auto removeObjectChar = [](QString &&text) {
|
||||||
|
return text.replace(QChar::ObjectReplacementCharacter, "");
|
||||||
|
};
|
||||||
|
|
||||||
|
mimeData->setData("text/html", removeObjectChar(fragment.toHtml()).toUtf8());
|
||||||
|
mimeData->setData("text/markdown", removeObjectChar(fragment.toMarkdown()).toUtf8());
|
||||||
|
{
|
||||||
|
QBuffer buffer;
|
||||||
|
QTextDocumentWriter writer(&buffer, "ODF");
|
||||||
|
if (writer.write(fragment)) {
|
||||||
|
buffer.close();
|
||||||
|
mimeData->setData("application/vnd.oasis.opendocument.text", buffer.data());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mimeData->setText(removeObjectChar(fragment.toPlainText()));
|
||||||
|
|
||||||
|
return mimeData;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
|
||||||
#include "markdownbrowser.moc"
|
#include "markdownbrowser.moc"
|
||||||
|
@@ -42,6 +42,8 @@ protected:
|
|||||||
void changeEvent(QEvent *event) override;
|
void changeEvent(QEvent *event) override;
|
||||||
void mousePressEvent(QMouseEvent *event) override;
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
|
|
||||||
|
QMimeData *createMimeDataFromSelection() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void handleAnchorClicked(const QUrl &link);
|
void handleAnchorClicked(const QUrl &link);
|
||||||
void postProcessDocument(bool firstTime);
|
void postProcessDocument(bool firstTime);
|
||||||
|
Reference in New Issue
Block a user