forked from qt-creator/qt-creator
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:
@@ -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);
|
||||
|
||||
@@ -347,6 +347,7 @@ public:
|
||||
|
||||
void cutLine();
|
||||
void copyLine();
|
||||
void copyWithHtml();
|
||||
void duplicateSelection();
|
||||
void duplicateSelectionAndComment();
|
||||
void deleteLine();
|
||||
@@ -512,6 +513,7 @@ protected:
|
||||
void dragEnterEvent(QDragEnterEvent *e) override;
|
||||
|
||||
QMimeData *createMimeDataFromSelection() const override;
|
||||
QMimeData *createMimeDataFromSelection(bool withHtml) const;
|
||||
bool canInsertFromMimeData(const QMimeData *source) const override;
|
||||
void insertFromMimeData(const QMimeData *source) override;
|
||||
void dragLeaveEvent(QDragLeaveEvent *e) override;
|
||||
|
||||
@@ -104,6 +104,7 @@ public:
|
||||
QAction *m_undoAction = nullptr;
|
||||
QAction *m_redoAction = nullptr;
|
||||
QAction *m_copyAction = nullptr;
|
||||
QAction *m_copyHtmlAction = nullptr;
|
||||
QAction *m_cutAction = nullptr;
|
||||
QAction *m_autoIndentAction = nullptr;
|
||||
QAction *m_autoFormatAction = nullptr;
|
||||
@@ -307,6 +308,10 @@ void TextEditorActionHandlerPrivate::createActions()
|
||||
[] (TextEditorWidget *w) { w->copyLine(); }, false, tr("Copy &Line"),
|
||||
QKeySequence(tr("Ctrl+Ins")),
|
||||
G_EDIT_TEXT, advancedEditMenu);
|
||||
m_copyHtmlAction = registerAction(COPY_WITH_HTML,
|
||||
[] (TextEditorWidget *w) { w->copyWithHtml(); }, true, tr("Copy With Highlighting"),
|
||||
QKeySequence(), G_EDIT_TEXT, advancedEditMenu);
|
||||
|
||||
registerAction(ADD_CURSORS_TO_LINE_ENDS,
|
||||
[] (TextEditorWidget *w) { w->addCursorsToLineEnds(); }, false, tr("Create Cursors at Selected Line Ends"),
|
||||
QKeySequence(tr("Alt+Shift+I")),
|
||||
@@ -496,6 +501,8 @@ void TextEditorActionHandlerPrivate::updateCopyAction(bool hasCopyableText)
|
||||
&& !m_currentEditorWidget->isReadOnly());
|
||||
if (m_copyAction)
|
||||
m_copyAction->setEnabled(hasCopyableText);
|
||||
if (m_copyHtmlAction)
|
||||
m_copyHtmlAction->setEnabled(hasCopyableText);
|
||||
}
|
||||
|
||||
void TextEditorActionHandlerPrivate::updateCurrentEditor(Core::IEditor *editor)
|
||||
|
||||
@@ -150,6 +150,7 @@ const char MOVE_LINE_UP[] = "TextEditor.MoveLineUp";
|
||||
const char MOVE_LINE_DOWN[] = "TextEditor.MoveLineDown";
|
||||
const char COPY_LINE_UP[] = "TextEditor.CopyLineUp";
|
||||
const char COPY_LINE_DOWN[] = "TextEditor.CopyLineDown";
|
||||
const char COPY_WITH_HTML[] = "TextEditor.CopyWithHtml";
|
||||
const char JOIN_LINES[] = "TextEditor.JoinLines";
|
||||
const char INSERT_LINE_ABOVE[] = "TextEditor.InsertLineAboveCurrentLine";
|
||||
const char INSERT_LINE_BELOW[] = "TextEditor.InsertLineBelowCurrentLine";
|
||||
|
||||
Reference in New Issue
Block a user