forked from qt-creator/qt-creator
Omit separator lines when copying selected text
In addition rename int start -> startPosition and int end -> endPosition to avoid a name clash with QTextBlock start inside BaseTextEditorWidget::createMimeDataFromSelection(). Change-Id: I7f54e4046913b5d5d9ddd3c07fd2747b4ca6f3fb Reviewed-by: hjk <hjk121@nokiamail.com> Reviewed-by: David Schulz <david.schulz@digia.com>
This commit is contained in:
@@ -97,6 +97,7 @@ protected:
|
||||
virtual int lineNumberDigits() const;
|
||||
virtual bool selectionVisible(int blockNumber) const;
|
||||
virtual bool replacementVisible(int blockNumber) const;
|
||||
QString plainTextFromSelection(const QTextCursor &cursor) const;
|
||||
virtual void paintEvent(QPaintEvent *e);
|
||||
virtual void scrollContentsBy(int dx, int dy);
|
||||
|
||||
@@ -137,6 +138,41 @@ bool DiffViewEditorWidget::replacementVisible(int blockNumber) const
|
||||
return m_skippedLines.value(blockNumber);
|
||||
}
|
||||
|
||||
QString DiffViewEditorWidget::plainTextFromSelection(const QTextCursor &cursor) const
|
||||
{
|
||||
const int startPosition = cursor.selectionStart();
|
||||
const int endPosition = cursor.selectionEnd();
|
||||
if (startPosition == endPosition)
|
||||
return QString(); // no selection
|
||||
|
||||
QTextBlock startBlock = document()->findBlock(startPosition);
|
||||
QTextBlock endBlock = document()->findBlock(endPosition);
|
||||
QTextBlock block = startBlock;
|
||||
QString text;
|
||||
bool textInserted = false;
|
||||
while (block.isValid() && block.blockNumber() <= endBlock.blockNumber()) {
|
||||
if (selectionVisible(block.blockNumber())) {
|
||||
if (block == startBlock) {
|
||||
if (block == endBlock)
|
||||
text = cursor.selectedText(); // just one line text
|
||||
else
|
||||
text = block.text().mid(startPosition - block.position());
|
||||
} else {
|
||||
if (textInserted)
|
||||
text += QLatin1Char('\n');
|
||||
if (block == endBlock)
|
||||
text += block.text().left(endPosition - block.position());
|
||||
else
|
||||
text += block.text();
|
||||
}
|
||||
textInserted = true;
|
||||
}
|
||||
block = block.next();
|
||||
}
|
||||
|
||||
return convertToPlainText(text);
|
||||
}
|
||||
|
||||
void DiffViewEditorWidget::setLineNumber(int blockNumber, const QString &lineNumber)
|
||||
{
|
||||
m_lineNumbers.insert(blockNumber, lineNumber);
|
||||
|
||||
Reference in New Issue
Block a user