Editor: remove html from default mime data

This is known to be expensive and a lot of users actually prefer plain
text in the copied mime data to avoid unwanted coloring in 3rd party
tools. Add a separate action (Edit > Advanced > Copy With Highlighting)
that preserves the original functionality.

Change-Id: I0f3c529146ab94d0cd9ce9e3b997c8501a577f03
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
David Schulz
2022-08-30 15:34:20 +02:00
parent 77b5613cd9
commit 8fab2011ba
4 changed files with 23 additions and 1 deletions

View File

@@ -6838,6 +6838,13 @@ void TextEditorWidget::copyLine()
copy();
}
void TextEditorWidget::copyWithHtml()
{
if (!multiTextCursor().hasSelection())
return;
QGuiApplication::clipboard()->setMimeData(createMimeDataFromSelection(true));
}
void TextEditorWidgetPrivate::addCursorsToLineEnds()
{
MultiTextCursor multiCursor = q->multiTextCursor();
@@ -7522,6 +7529,11 @@ void TextEditorWidget::switchUtf8bom()
}
QMimeData *TextEditorWidget::createMimeDataFromSelection() const
{
return createMimeDataFromSelection(false);
}
QMimeData *TextEditorWidget::createMimeDataFromSelection(bool withHtml) const
{
if (multiTextCursor().hasSelection()) {
auto mimeData = new QMimeData;
@@ -7530,7 +7542,7 @@ QMimeData *TextEditorWidget::createMimeDataFromSelection() const
mimeData->setText(text);
// Copy the selected text as HTML
{
if (withHtml) {
// Create a new document from the selected text document fragment
auto tempDocument = new QTextDocument;
QTextCursor tempCursor(tempDocument);