forked from qt-creator/qt-creator
ProjectExplorer: Fix copying filtered-out text
Invisible blocks must be excluded. Fixes: QTCREATORBUG-23425 Change-Id: I93a253bd47820d6eb6feea90056c76091e376070 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -33,6 +33,8 @@
|
||||
#include <utils/synchronousprocess.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QCursor>
|
||||
#include <QMimeData>
|
||||
#include <QPointer>
|
||||
#include <QRegularExpression>
|
||||
#include <QScrollBar>
|
||||
@@ -512,6 +514,33 @@ bool OutputWindow::isScrollbarAtBottom() const
|
||||
return verticalScrollBar()->value() == verticalScrollBar()->maximum();
|
||||
}
|
||||
|
||||
QMimeData *OutputWindow::createMimeDataFromSelection() const
|
||||
{
|
||||
const auto mimeData = new QMimeData;
|
||||
QString content;
|
||||
const int selStart = textCursor().selectionStart();
|
||||
const int selEnd = textCursor().selectionEnd();
|
||||
const QTextBlock firstBlock = document()->findBlock(selStart);
|
||||
const QTextBlock lastBlock = document()->findBlock(selEnd);
|
||||
for (QTextBlock curBlock = firstBlock; curBlock != lastBlock; curBlock = curBlock.next()) {
|
||||
if (!curBlock.isVisible())
|
||||
continue;
|
||||
if (curBlock == firstBlock)
|
||||
content += curBlock.text().mid(selStart - firstBlock.position());
|
||||
else
|
||||
content += curBlock.text();
|
||||
content += '\n';
|
||||
}
|
||||
if (lastBlock.isValid() && lastBlock.isVisible()) {
|
||||
if (firstBlock == lastBlock)
|
||||
content = textCursor().selectedText();
|
||||
else
|
||||
content += lastBlock.text().mid(0, selEnd - lastBlock.position());
|
||||
}
|
||||
mimeData->setText(content);
|
||||
return mimeData;
|
||||
}
|
||||
|
||||
void OutputWindow::clear()
|
||||
{
|
||||
d->enforceNewline = false;
|
||||
|
@@ -66,8 +66,6 @@ public:
|
||||
void grayOutOldContent();
|
||||
void clear();
|
||||
|
||||
void showEvent(QShowEvent *) override;
|
||||
|
||||
void scrollToBottom();
|
||||
|
||||
void setMaxCharCount(int count);
|
||||
@@ -94,14 +92,16 @@ public slots:
|
||||
protected:
|
||||
bool isScrollbarAtBottom() const;
|
||||
|
||||
private:
|
||||
QMimeData *createMimeDataFromSelection() const override;
|
||||
void keyPressEvent(QKeyEvent *ev) override;
|
||||
void mousePressEvent(QMouseEvent *e) override;
|
||||
void mouseReleaseEvent(QMouseEvent *e) override;
|
||||
void mouseMoveEvent(QMouseEvent *e) override;
|
||||
void resizeEvent(QResizeEvent *e) override;
|
||||
void keyPressEvent(QKeyEvent *ev) override;
|
||||
void showEvent(QShowEvent *) override;
|
||||
void wheelEvent(QWheelEvent *e) override;
|
||||
|
||||
private:
|
||||
using QPlainTextEdit::setFont; // call setBaseFont instead, which respects the zoom factor
|
||||
QTimer m_scrollTimer;
|
||||
QElapsedTimer m_lastMessage;
|
||||
|
Reference in New Issue
Block a user