forked from qt-creator/qt-creator
Get rid of QChar::LineSeparator
It was causing troubles while scrolling. Replace it with \n and hack selection. Simplify the code. Now every line is a separate block. Prepare for expanding skipped lines. Change-Id: I8d305681c575abdaaf9cdbf26de864dd3a906d3a Reviewed-by: David Schulz <david.schulz@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
@@ -64,6 +64,7 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
////////////////////////
|
////////////////////////
|
||||||
|
|
||||||
class DiffViewEditorWidget : public SnippetEditorWidget
|
class DiffViewEditorWidget : public SnippetEditorWidget
|
||||||
@@ -79,27 +80,31 @@ public:
|
|||||||
return const_cast<QTextCodec *>(baseTextDocument()->codec());
|
return const_cast<QTextCodec *>(baseTextDocument()->codec());
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<int, QMap<int, int> > skippedLines() const { return m_skippedLines; }
|
QMap<int, int> skippedLines() const { return m_skippedLines; }
|
||||||
|
|
||||||
void setLineNumber(int blockNumber, const QString &lineNumber);
|
void setLineNumber(int blockNumber, const QString &lineNumber);
|
||||||
void setSkippedLines(int blockNumber, int lineInBlock, int skippedLines) { m_skippedLines[blockNumber][lineInBlock] = skippedLines; }
|
void setSkippedLines(int blockNumber, int skippedLines) { m_skippedLines[blockNumber] = skippedLines; }
|
||||||
|
void setSeparator(int blockNumber, bool separator) { m_separators[blockNumber] = separator; }
|
||||||
void clearLineNumbers();
|
void clearLineNumbers();
|
||||||
void clearSkippedLines() { m_skippedLines.clear(); }
|
void clearSkippedLines() { m_skippedLines.clear(); }
|
||||||
|
void clearSeparators() { m_separators.clear(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual int extraAreaWidth(int *markWidthPtr = 0) const { return BaseTextEditorWidget::extraAreaWidth(markWidthPtr); }
|
virtual int extraAreaWidth(int *markWidthPtr = 0) const { return BaseTextEditorWidget::extraAreaWidth(markWidthPtr); }
|
||||||
BaseTextEditor *createEditor() { return new DiffViewEditorEditable(this); }
|
BaseTextEditor *createEditor() { return new DiffViewEditorEditable(this); }
|
||||||
virtual QString lineNumber(int blockNumber) const;
|
virtual QString lineNumber(int blockNumber) const;
|
||||||
int lineNumberTopPositionOffset(int blockNumber) const;
|
|
||||||
virtual int lineNumberDigits() const;
|
virtual int lineNumberDigits() const;
|
||||||
|
virtual bool selectionVisible(int blockNumber) const;
|
||||||
virtual void paintEvent(QPaintEvent *e);
|
virtual void paintEvent(QPaintEvent *e);
|
||||||
virtual void scrollContentsBy(int dx, int dy);
|
virtual void scrollContentsBy(int dx, int dy);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMap<int, QString> m_lineNumbers;
|
QMap<int, QString> m_lineNumbers;
|
||||||
int m_lineNumberDigits;
|
int m_lineNumberDigits;
|
||||||
// block number, line in block, skipped lines
|
// block number, skipped lines
|
||||||
QMap<int, QMap<int, int> > m_skippedLines;
|
QMap<int, int> m_skippedLines;
|
||||||
|
// block number, separator
|
||||||
|
QMap<int, bool> m_separators;
|
||||||
};
|
};
|
||||||
|
|
||||||
DiffViewEditorWidget::DiffViewEditorWidget(QWidget *parent)
|
DiffViewEditorWidget::DiffViewEditorWidget(QWidget *parent)
|
||||||
@@ -114,27 +119,16 @@ QString DiffViewEditorWidget::lineNumber(int blockNumber) const
|
|||||||
return m_lineNumbers.value(blockNumber);
|
return m_lineNumbers.value(blockNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DiffViewEditorWidget::lineNumberTopPositionOffset(int blockNumber) const
|
|
||||||
{
|
|
||||||
int offset = 0;
|
|
||||||
const QFontMetrics fm(extraArea()->font());
|
|
||||||
int i = 0;
|
|
||||||
const QString text = document()->findBlockByNumber(blockNumber).text();
|
|
||||||
while (i < text.count()) {
|
|
||||||
if (text.at(i) != QChar::LineSeparator)
|
|
||||||
break;
|
|
||||||
offset += fm.height();
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int DiffViewEditorWidget::lineNumberDigits() const
|
int DiffViewEditorWidget::lineNumberDigits() const
|
||||||
{
|
{
|
||||||
return m_lineNumberDigits;
|
return m_lineNumberDigits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DiffViewEditorWidget::selectionVisible(int blockNumber) const
|
||||||
|
{
|
||||||
|
return !m_separators.value(blockNumber, false);
|
||||||
|
}
|
||||||
|
|
||||||
void DiffViewEditorWidget::setLineNumber(int blockNumber, const QString &lineNumber)
|
void DiffViewEditorWidget::setLineNumber(int blockNumber, const QString &lineNumber)
|
||||||
{
|
{
|
||||||
m_lineNumbers.insert(blockNumber, lineNumber);
|
m_lineNumbers.insert(blockNumber, lineNumber);
|
||||||
@@ -163,7 +157,7 @@ void DiffViewEditorWidget::paintEvent(QPaintEvent *e)
|
|||||||
QTextBlock firstBlock = firstVisibleBlock();
|
QTextBlock firstBlock = firstVisibleBlock();
|
||||||
QTextBlock currentBlock = firstBlock;
|
QTextBlock currentBlock = firstBlock;
|
||||||
|
|
||||||
QMap<int, QMap<int, int> > skipped = skippedLines();
|
QMap<int, int> skipped = skippedLines();
|
||||||
|
|
||||||
while (currentBlock.isValid()) {
|
while (currentBlock.isValid()) {
|
||||||
if (currentBlock.isVisible()) {
|
if (currentBlock.isVisible()) {
|
||||||
@@ -176,17 +170,13 @@ void DiffViewEditorWidget::paintEvent(QPaintEvent *e)
|
|||||||
if (bottom >= e->rect().top()) {
|
if (bottom >= e->rect().top()) {
|
||||||
QTextLayout *layout = currentBlock.layout();
|
QTextLayout *layout = currentBlock.layout();
|
||||||
|
|
||||||
QMap<int, int> skippedInBlock = skipped.value(currentBlock.blockNumber());
|
int skippedBefore = skipped.value(currentBlock.blockNumber());
|
||||||
QMapIterator<int, int> itLines(skippedInBlock);
|
if (skippedBefore) {
|
||||||
while (itLines.hasNext()) {
|
|
||||||
itLines.next();
|
|
||||||
|
|
||||||
painter.save();
|
painter.save();
|
||||||
painter.setPen(palette().foreground().color());
|
painter.setPen(palette().foreground().color());
|
||||||
QTextLine textLine = layout->lineAt(itLines.key());
|
QTextLine textLine = layout->lineAt(0);
|
||||||
// QRectF lineRect = textLine.naturalTextRect().translated(offset.x(), top);
|
|
||||||
QRectF lineRect = textLine.naturalTextRect().translated(0, top);
|
QRectF lineRect = textLine.naturalTextRect().translated(0, top);
|
||||||
QString skippedRowsText = tr("Skipped %n lines...", 0, itLines.value());
|
QString skippedRowsText = tr("Skipped %n lines...", 0, skippedBefore);
|
||||||
QFontMetrics fm(font());
|
QFontMetrics fm(font());
|
||||||
const int textWidth = fm.width(skippedRowsText);
|
const int textWidth = fm.width(skippedRowsText);
|
||||||
painter.drawText(QPointF(lineRect.right()
|
painter.drawText(QPointF(lineRect.right()
|
||||||
@@ -206,9 +196,7 @@ void DiffViewEditorWidget::paintEvent(QPaintEvent *e)
|
|||||||
DiffEditorWidget::DiffEditorWidget(QWidget *parent)
|
DiffEditorWidget::DiffEditorWidget(QWidget *parent)
|
||||||
: QWidget(parent),
|
: QWidget(parent),
|
||||||
m_contextLinesNumber(1),
|
m_contextLinesNumber(1),
|
||||||
m_ignoreWhitespaces(true),
|
m_ignoreWhitespaces(true)
|
||||||
m_leftSafePosHack(-1),
|
|
||||||
m_rightSafePosHack(-1)
|
|
||||||
{
|
{
|
||||||
TextEditor::TextEditorSettings *settings = TextEditorSettings::instance();
|
TextEditor::TextEditorSettings *settings = TextEditorSettings::instance();
|
||||||
|
|
||||||
@@ -631,22 +619,16 @@ FileData DiffEditorWidget::calculateContextData(const ChunkData &originalData) c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
i = 0;
|
i = 0;
|
||||||
int skippedLines = 0;
|
|
||||||
int leftCharCounter = 0;
|
int leftCharCounter = 0;
|
||||||
int rightCharCounter = 0;
|
int rightCharCounter = 0;
|
||||||
int leftCharSkipped = 0;
|
|
||||||
int rightCharSkipped = 0;
|
|
||||||
int chunkOffset = 0;
|
|
||||||
QMap<int, int>::ConstIterator leftChangedIt = originalData.changedLeftPositions.constBegin();
|
QMap<int, int>::ConstIterator leftChangedIt = originalData.changedLeftPositions.constBegin();
|
||||||
QMap<int, int>::ConstIterator rightChangedIt = originalData.changedRightPositions.constBegin();
|
QMap<int, int>::ConstIterator rightChangedIt = originalData.changedRightPositions.constBegin();
|
||||||
while (i < originalData.rows.count()) {
|
while (i < originalData.rows.count()) {
|
||||||
if (!hiddenRows.contains(i)) {
|
if (!hiddenRows.contains(i)) {
|
||||||
ChunkData chunkData;
|
ChunkData chunkData;
|
||||||
if (skippedLines)
|
int leftOffset = leftCharCounter;
|
||||||
chunkOffset++; // for chunk line
|
int rightOffset = rightCharCounter;
|
||||||
chunkData.leftOffset = leftCharCounter;
|
chunkData.alwaysShown = true;
|
||||||
chunkData.rightOffset = rightCharCounter;
|
|
||||||
chunkData.skippedLinesBefore = skippedLines;
|
|
||||||
while (i < originalData.rows.count()) {
|
while (i < originalData.rows.count()) {
|
||||||
if (hiddenRows.contains(i))
|
if (hiddenRows.contains(i))
|
||||||
break;
|
break;
|
||||||
@@ -658,47 +640,42 @@ FileData DiffEditorWidget::calculateContextData(const ChunkData &originalData) c
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
while (leftChangedIt != originalData.changedLeftPositions.constEnd()) {
|
while (leftChangedIt != originalData.changedLeftPositions.constEnd()) {
|
||||||
if (leftChangedIt.key() < chunkData.leftOffset
|
if (leftChangedIt.key() < leftOffset
|
||||||
|| leftChangedIt.key() > leftCharCounter)
|
|| leftChangedIt.key() > leftCharCounter)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
const int startPos = leftChangedIt.key() - leftCharSkipped + chunkOffset;
|
const int startPos = leftChangedIt.key();
|
||||||
const int endPos = leftChangedIt.value() - leftCharSkipped + chunkOffset;
|
const int endPos = leftChangedIt.value();
|
||||||
chunkData.changedLeftPositions.insert(startPos, endPos);
|
chunkData.changedLeftPositions.insert(startPos, endPos);
|
||||||
leftChangedIt++;
|
leftChangedIt++;
|
||||||
}
|
}
|
||||||
while (rightChangedIt != originalData.changedRightPositions.constEnd()) {
|
while (rightChangedIt != originalData.changedRightPositions.constEnd()) {
|
||||||
if (rightChangedIt.key() < chunkData.rightOffset
|
if (rightChangedIt.key() < rightOffset
|
||||||
|| rightChangedIt.key() > rightCharCounter)
|
|| rightChangedIt.key() > rightCharCounter)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
const int startPos = rightChangedIt.key() - rightCharSkipped + chunkOffset;
|
const int startPos = rightChangedIt.key();
|
||||||
const int endPos = rightChangedIt.value() - rightCharSkipped + chunkOffset;
|
const int endPos = rightChangedIt.value();
|
||||||
chunkData.changedRightPositions.insert(startPos, endPos);
|
chunkData.changedRightPositions.insert(startPos, endPos);
|
||||||
rightChangedIt++;
|
rightChangedIt++;
|
||||||
}
|
}
|
||||||
fileData.chunks.append(chunkData);
|
fileData.chunks.append(chunkData);
|
||||||
skippedLines = 0;
|
|
||||||
} else {
|
} else {
|
||||||
const int leftChars = originalData.rows.at(i).leftLine.text.count() + 1;
|
|
||||||
const int rightChars = originalData.rows.at(i).rightLine.text.count() + 1;
|
|
||||||
leftCharCounter += leftChars;
|
|
||||||
rightCharCounter += rightChars;
|
|
||||||
leftCharSkipped += leftChars;
|
|
||||||
rightCharSkipped += rightChars;
|
|
||||||
i++;
|
|
||||||
skippedLines++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (skippedLines) {
|
|
||||||
ChunkData chunkData;
|
ChunkData chunkData;
|
||||||
chunkData.leftOffset = leftCharCounter;
|
chunkData.alwaysShown = false;
|
||||||
chunkData.rightOffset = rightCharCounter;
|
while (i < originalData.rows.count()) {
|
||||||
chunkData.skippedLinesBefore = skippedLines;
|
if (!hiddenRows.contains(i))
|
||||||
|
break;
|
||||||
|
RowData rowData = originalData.rows.at(i);
|
||||||
|
chunkData.rows.append(rowData);
|
||||||
|
|
||||||
|
leftCharCounter += rowData.leftLine.text.count() + 1; // +1 for separator or for '\n', each line has one of it
|
||||||
|
rightCharCounter += rowData.rightLine.text.count() + 1; // +1 for separator or for '\n', each line has one of it
|
||||||
|
i++;
|
||||||
|
}
|
||||||
fileData.chunks.append(chunkData);
|
fileData.chunks.append(chunkData);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return fileData;
|
return fileData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -706,123 +683,64 @@ void DiffEditorWidget::showDiff()
|
|||||||
{
|
{
|
||||||
// QTime time;
|
// QTime time;
|
||||||
// time.start();
|
// time.start();
|
||||||
|
|
||||||
|
// TODO: remember the line number of the line in the middle
|
||||||
const int verticalValue = m_leftEditor->verticalScrollBar()->value();
|
const int verticalValue = m_leftEditor->verticalScrollBar()->value();
|
||||||
const int leftHorizontalValue = m_leftEditor->horizontalScrollBar()->value();
|
const int leftHorizontalValue = m_leftEditor->horizontalScrollBar()->value();
|
||||||
const int rightHorizontalValue = m_rightEditor->horizontalScrollBar()->value();
|
const int rightHorizontalValue = m_rightEditor->horizontalScrollBar()->value();
|
||||||
|
|
||||||
// Ugly hack starts here
|
|
||||||
// When the cursor stays on the line with QChar::LineSeparator
|
|
||||||
// the new inserted text will have the background taken from that line.
|
|
||||||
if (m_leftSafePosHack >= 0) {
|
|
||||||
QTextCursor cursor = m_leftEditor->textCursor();
|
|
||||||
cursor.setPosition(m_leftSafePosHack);
|
|
||||||
m_leftEditor->setTextCursor(cursor);
|
|
||||||
m_leftSafePosHack = -1;
|
|
||||||
}
|
|
||||||
if (m_rightSafePosHack >= 0) {
|
|
||||||
QTextCursor cursor = m_rightEditor->textCursor();
|
|
||||||
cursor.setPosition(m_rightSafePosHack);
|
|
||||||
m_rightEditor->setTextCursor(cursor);
|
|
||||||
m_rightSafePosHack = -1;
|
|
||||||
}
|
|
||||||
// Ugly hack ends here
|
|
||||||
|
|
||||||
m_leftEditor->clear();
|
m_leftEditor->clear();
|
||||||
m_rightEditor->clear();
|
m_rightEditor->clear();
|
||||||
m_leftEditor->clearLineNumbers();
|
m_leftEditor->clearLineNumbers();
|
||||||
m_rightEditor->clearLineNumbers();
|
m_rightEditor->clearLineNumbers();
|
||||||
m_leftEditor->clearSkippedLines();
|
m_leftEditor->clearSkippedLines();
|
||||||
m_rightEditor->clearSkippedLines();
|
m_rightEditor->clearSkippedLines();
|
||||||
|
m_leftEditor->clearSeparators();
|
||||||
|
m_rightEditor->clearSeparators();
|
||||||
// int ela1 = time.elapsed();
|
// int ela1 = time.elapsed();
|
||||||
|
|
||||||
QString leftText, rightText;
|
QString leftText, rightText;
|
||||||
bool leftStartWithNewLine = false;
|
|
||||||
bool rightStartWithNewLine = false;
|
|
||||||
int leftLineNumber = 0;
|
int leftLineNumber = 0;
|
||||||
int leftBlockNumber = 0;
|
|
||||||
int rightLineNumber = 0;
|
int rightLineNumber = 0;
|
||||||
int rightBlockNumber = 0;
|
int blockNumber = 0;
|
||||||
int leftPos = 0;
|
QChar separator = QLatin1Char('\n');
|
||||||
int rightPos = 0;
|
|
||||||
int leftSeparatorCount = 0;
|
|
||||||
int rightSeparatorCount = 0;
|
|
||||||
for (int i = 0; i < m_contextFileData.chunks.count(); i++) {
|
for (int i = 0; i < m_contextFileData.chunks.count(); i++) {
|
||||||
ChunkData chunkData = m_contextFileData.chunks.at(i);
|
ChunkData chunkData = m_contextFileData.chunks.at(i);
|
||||||
leftLineNumber += chunkData.skippedLinesBefore;
|
if (!chunkData.alwaysShown) {
|
||||||
rightLineNumber += chunkData.skippedLinesBefore;
|
const int skippedLines = chunkData.rows.count();
|
||||||
|
// leftLineNumber += skippedLines;
|
||||||
if (chunkData.skippedLinesBefore) {
|
// rightLineNumber += skippedLines;
|
||||||
m_leftEditor->setSkippedLines(leftBlockNumber, leftSeparatorCount, chunkData.skippedLinesBefore);
|
m_leftEditor->setSkippedLines(blockNumber, skippedLines);
|
||||||
leftSeparatorCount++;
|
m_rightEditor->setSkippedLines(blockNumber, skippedLines);
|
||||||
m_rightEditor->setSkippedLines(rightBlockNumber, rightSeparatorCount, chunkData.skippedLinesBefore);
|
m_leftEditor->setSeparator(blockNumber, true);
|
||||||
rightSeparatorCount++;
|
m_rightEditor->setSeparator(blockNumber, true);
|
||||||
|
leftText += separator;
|
||||||
|
rightText += separator;
|
||||||
|
blockNumber++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int j = 0; j < chunkData.rows.count(); j++) {
|
for (int j = 0; j < chunkData.rows.count(); j++) {
|
||||||
RowData rowData = chunkData.rows.at(j);
|
RowData rowData = chunkData.rows.at(j);
|
||||||
TextLineData leftLineData = rowData.leftLine;
|
TextLineData leftLineData = rowData.leftLine;
|
||||||
TextLineData rightLineData = rowData.rightLine;
|
TextLineData rightLineData = rowData.rightLine;
|
||||||
|
|
||||||
if (leftLineData.textLineType == TextLineData::TextLine) {
|
if (leftLineData.textLineType == TextLineData::TextLine) {
|
||||||
if (leftStartWithNewLine) {
|
|
||||||
leftText += QLatin1Char('\n');
|
|
||||||
leftPos++;
|
|
||||||
}
|
|
||||||
if (leftSeparatorCount) {
|
|
||||||
leftText += QString(leftSeparatorCount, QChar::LineSeparator);
|
|
||||||
leftSeparatorCount = 0;
|
|
||||||
leftPos += leftSeparatorCount;
|
|
||||||
}
|
|
||||||
if (m_leftSafePosHack < 0)
|
|
||||||
m_leftSafePosHack = leftPos;
|
|
||||||
leftPos += leftLineData.text.count();
|
|
||||||
leftText += leftLineData.text;
|
leftText += leftLineData.text;
|
||||||
leftStartWithNewLine = true;
|
|
||||||
leftLineNumber++;
|
leftLineNumber++;
|
||||||
m_leftEditor->setLineNumber(leftBlockNumber, QString::number(leftLineNumber));
|
m_leftEditor->setLineNumber(blockNumber, QString::number(leftLineNumber));
|
||||||
leftBlockNumber++;
|
|
||||||
} else if (leftLineData.textLineType == TextLineData::Separator) {
|
} else if (leftLineData.textLineType == TextLineData::Separator) {
|
||||||
leftSeparatorCount++;
|
m_leftEditor->setSeparator(blockNumber, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rightLineData.textLineType == TextLineData::TextLine) {
|
if (rightLineData.textLineType == TextLineData::TextLine) {
|
||||||
if (rightStartWithNewLine) {
|
|
||||||
rightText += QLatin1Char('\n');
|
|
||||||
rightPos++;
|
|
||||||
}
|
|
||||||
if (rightSeparatorCount) {
|
|
||||||
rightText += QString(rightSeparatorCount, QChar::LineSeparator);
|
|
||||||
rightSeparatorCount = 0;
|
|
||||||
rightPos += rightSeparatorCount;
|
|
||||||
}
|
|
||||||
if (m_rightSafePosHack < 0)
|
|
||||||
m_rightSafePosHack = rightPos;
|
|
||||||
rightPos += leftLineData.text.count();
|
|
||||||
rightText += rightLineData.text;
|
rightText += rightLineData.text;
|
||||||
rightStartWithNewLine = true;
|
|
||||||
rightLineNumber++;
|
rightLineNumber++;
|
||||||
m_rightEditor->setLineNumber(rightBlockNumber, QString::number(rightLineNumber));
|
m_rightEditor->setLineNumber(blockNumber, QString::number(rightLineNumber));
|
||||||
rightBlockNumber++;
|
|
||||||
} else if (rightLineData.textLineType == TextLineData::Separator) {
|
} else if (rightLineData.textLineType == TextLineData::Separator) {
|
||||||
rightSeparatorCount++;
|
m_rightEditor->setSeparator(blockNumber, true);
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if (i == m_contextFileData.chunks.count() - 1) {
|
|
||||||
if (leftSeparatorCount) {
|
|
||||||
if (leftStartWithNewLine) {
|
|
||||||
leftText += QLatin1Char('\n');
|
|
||||||
leftPos++;
|
|
||||||
}
|
|
||||||
leftText += QString(leftSeparatorCount, QChar::LineSeparator);
|
|
||||||
}
|
|
||||||
if (rightSeparatorCount) {
|
|
||||||
if (rightStartWithNewLine) {
|
|
||||||
rightText += QLatin1Char('\n');
|
|
||||||
rightPos++;
|
|
||||||
}
|
|
||||||
rightText += QString(rightSeparatorCount, QChar::LineSeparator);
|
|
||||||
}
|
}
|
||||||
|
leftText += separator;
|
||||||
|
rightText += separator;
|
||||||
|
blockNumber++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// int ela2 = time.elapsed();
|
// int ela2 = time.elapsed();
|
||||||
@@ -834,6 +752,38 @@ void DiffEditorWidget::showDiff()
|
|||||||
// int ela4 = time.elapsed();
|
// int ela4 = time.elapsed();
|
||||||
|
|
||||||
colorDiff(m_contextFileData);
|
colorDiff(m_contextFileData);
|
||||||
|
|
||||||
|
blockNumber = 0;
|
||||||
|
for (int i = 0; i < m_contextFileData.chunks.count(); i++) {
|
||||||
|
ChunkData chunkData = m_contextFileData.chunks.at(i);
|
||||||
|
if (!chunkData.alwaysShown) {
|
||||||
|
blockNumber++;
|
||||||
|
QTextBlock leftBlock = m_leftEditor->document()->findBlockByNumber(blockNumber);
|
||||||
|
for (int j = 0; j < chunkData.rows.count(); j++) {
|
||||||
|
leftBlock.setVisible(false);
|
||||||
|
leftBlock.setLineCount(0);
|
||||||
|
leftBlock = leftBlock.next();
|
||||||
|
}
|
||||||
|
QTextBlock rightBlock = m_rightEditor->document()->findBlockByNumber(blockNumber);
|
||||||
|
for (int j = 0; j < chunkData.rows.count(); j++) {
|
||||||
|
rightBlock.setVisible(false);
|
||||||
|
rightBlock.setLineCount(0);
|
||||||
|
rightBlock = rightBlock.next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
blockNumber += chunkData.rows.count();
|
||||||
|
}
|
||||||
|
BaseTextDocumentLayout *leftLayout = qobject_cast<BaseTextDocumentLayout *>(m_leftEditor->document()->documentLayout());
|
||||||
|
if (leftLayout) {
|
||||||
|
leftLayout->requestUpdate();
|
||||||
|
leftLayout->emitDocumentSizeChanged();
|
||||||
|
}
|
||||||
|
BaseTextDocumentLayout *rightLayout = qobject_cast<BaseTextDocumentLayout *>(m_rightEditor->document()->documentLayout());
|
||||||
|
if (rightLayout) {
|
||||||
|
rightLayout->requestUpdate();
|
||||||
|
rightLayout->emitDocumentSizeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
// int ela5 = time.elapsed();
|
// int ela5 = time.elapsed();
|
||||||
|
|
||||||
m_leftEditor->verticalScrollBar()->setValue(verticalValue);
|
m_leftEditor->verticalScrollBar()->setValue(verticalValue);
|
||||||
@@ -898,8 +848,10 @@ void DiffEditorWidget::colorDiff(const FileData &fileData)
|
|||||||
int leftPos = 0;
|
int leftPos = 0;
|
||||||
int rightPos = 0;
|
int rightPos = 0;
|
||||||
// startPos, endPos
|
// startPos, endPos
|
||||||
QMap<int, int> leftChangedPos;
|
QMap<int, int> leftLinePos;
|
||||||
QMap<int, int> rightChangedPos;
|
QMap<int, int> rightLinePos;
|
||||||
|
QMap<int, int> leftCharPos;
|
||||||
|
QMap<int, int> rightCharPos;
|
||||||
QMap<int, int> leftSkippedPos;
|
QMap<int, int> leftSkippedPos;
|
||||||
QMap<int, int> rightSkippedPos;
|
QMap<int, int> rightSkippedPos;
|
||||||
QMap<int, int> leftChunkPos;
|
QMap<int, int> leftChunkPos;
|
||||||
@@ -908,20 +860,36 @@ void DiffEditorWidget::colorDiff(const FileData &fileData)
|
|||||||
int rightLastDiffBlockStartPos = 0;
|
int rightLastDiffBlockStartPos = 0;
|
||||||
int leftLastSkippedBlockStartPos = 0;
|
int leftLastSkippedBlockStartPos = 0;
|
||||||
int rightLastSkippedBlockStartPos = 0;
|
int rightLastSkippedBlockStartPos = 0;
|
||||||
|
int chunkOffset = 0;
|
||||||
|
|
||||||
for (int i = 0; i < fileData.chunks.count(); i++) {
|
for (int i = 0; i < fileData.chunks.count(); i++) {
|
||||||
ChunkData chunkData = fileData.chunks.at(i);
|
ChunkData chunkData = fileData.chunks.at(i);
|
||||||
if (chunkData.skippedLinesBefore) {
|
if (!chunkData.alwaysShown) {
|
||||||
leftChunkPos[leftPos] = leftPos + 1;
|
leftChunkPos[leftPos] = leftPos + 1;
|
||||||
rightChunkPos[rightPos] = rightPos + 1;
|
rightChunkPos[rightPos] = rightPos + 1;
|
||||||
leftPos++; // for chunk line
|
leftPos++; // for chunk line
|
||||||
rightPos++; // for chunk line
|
rightPos++; // for chunk line
|
||||||
|
chunkOffset++;
|
||||||
}
|
}
|
||||||
leftLastDiffBlockStartPos = leftPos;
|
leftLastDiffBlockStartPos = leftPos;
|
||||||
rightLastDiffBlockStartPos = rightPos;
|
rightLastDiffBlockStartPos = rightPos;
|
||||||
leftLastSkippedBlockStartPos = leftPos;
|
leftLastSkippedBlockStartPos = leftPos;
|
||||||
rightLastSkippedBlockStartPos = rightPos;
|
rightLastSkippedBlockStartPos = rightPos;
|
||||||
|
|
||||||
|
QMapIterator<int, int> itLeft(chunkData.changedLeftPositions);
|
||||||
|
while (itLeft.hasNext()) {
|
||||||
|
itLeft.next();
|
||||||
|
|
||||||
|
leftCharPos[itLeft.key() + chunkOffset] = itLeft.value() + chunkOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
QMapIterator<int, int> itRight(chunkData.changedRightPositions);
|
||||||
|
while (itRight.hasNext()) {
|
||||||
|
itRight.next();
|
||||||
|
|
||||||
|
rightCharPos[itRight.key() + chunkOffset] = itRight.value() + chunkOffset;
|
||||||
|
}
|
||||||
|
|
||||||
for (int j = 0; j < chunkData.rows.count(); j++) {
|
for (int j = 0; j < chunkData.rows.count(); j++) {
|
||||||
RowData rowData = chunkData.rows.at(j);
|
RowData rowData = chunkData.rows.at(j);
|
||||||
|
|
||||||
@@ -930,14 +898,14 @@ void DiffEditorWidget::colorDiff(const FileData &fileData)
|
|||||||
|
|
||||||
if (!rowData.equal) {
|
if (!rowData.equal) {
|
||||||
if (rowData.leftLine.textLineType == TextLineData::TextLine) {
|
if (rowData.leftLine.textLineType == TextLineData::TextLine) {
|
||||||
leftChangedPos[leftLastDiffBlockStartPos] = leftPos;
|
leftLinePos[leftLastDiffBlockStartPos] = leftPos;
|
||||||
leftLastSkippedBlockStartPos = leftPos;
|
leftLastSkippedBlockStartPos = leftPos;
|
||||||
} else {
|
} else {
|
||||||
leftSkippedPos[leftLastSkippedBlockStartPos] = leftPos;
|
leftSkippedPos[leftLastSkippedBlockStartPos] = leftPos;
|
||||||
leftLastDiffBlockStartPos = leftPos;
|
leftLastDiffBlockStartPos = leftPos;
|
||||||
}
|
}
|
||||||
if (rowData.rightLine.textLineType == TextLineData::TextLine) {
|
if (rowData.rightLine.textLineType == TextLineData::TextLine) {
|
||||||
rightChangedPos[rightLastDiffBlockStartPos] = rightPos;
|
rightLinePos[rightLastDiffBlockStartPos] = rightPos;
|
||||||
rightLastSkippedBlockStartPos = rightPos;
|
rightLastSkippedBlockStartPos = rightPos;
|
||||||
} else {
|
} else {
|
||||||
rightSkippedPos[rightLastSkippedBlockStartPos] = rightPos;
|
rightSkippedPos[rightLastSkippedBlockStartPos] = rightPos;
|
||||||
@@ -956,26 +924,22 @@ void DiffEditorWidget::colorDiff(const FileData &fileData)
|
|||||||
QTextCursor rightCursor = m_rightEditor->textCursor();
|
QTextCursor rightCursor = m_rightEditor->textCursor();
|
||||||
|
|
||||||
QList<QTextEdit::ExtraSelection> leftSelections
|
QList<QTextEdit::ExtraSelection> leftSelections
|
||||||
= colorPositions(leftLineFormat, leftCursor, leftChangedPos);
|
= colorPositions(leftLineFormat, leftCursor, leftLinePos);
|
||||||
leftSelections
|
leftSelections
|
||||||
+= colorPositions(spanLineFormat, leftCursor, leftSkippedPos);
|
+= colorPositions(spanLineFormat, leftCursor, leftSkippedPos);
|
||||||
leftSelections
|
leftSelections
|
||||||
+= colorPositions(chunkLineFormat, leftCursor, leftChunkPos);
|
+= colorPositions(chunkLineFormat, leftCursor, leftChunkPos);
|
||||||
|
leftSelections
|
||||||
|
+= colorPositions(leftCharFormat, leftCursor, leftCharPos);
|
||||||
|
|
||||||
QList<QTextEdit::ExtraSelection> rightSelections
|
QList<QTextEdit::ExtraSelection> rightSelections
|
||||||
= colorPositions(rightLineFormat, rightCursor, rightChangedPos);
|
= colorPositions(rightLineFormat, rightCursor, rightLinePos);
|
||||||
rightSelections
|
rightSelections
|
||||||
+= colorPositions(spanLineFormat, rightCursor, rightSkippedPos);
|
+= colorPositions(spanLineFormat, rightCursor, rightSkippedPos);
|
||||||
rightSelections
|
rightSelections
|
||||||
+= colorPositions(chunkLineFormat, rightCursor, rightChunkPos);
|
+= colorPositions(chunkLineFormat, rightCursor, rightChunkPos);
|
||||||
|
|
||||||
for (int i = 0; i < fileData.chunks.count(); i++) {
|
|
||||||
ChunkData chunkData = fileData.chunks.at(i);
|
|
||||||
leftSelections
|
|
||||||
+= colorPositions(leftCharFormat, leftCursor, chunkData.changedLeftPositions);
|
|
||||||
rightSelections
|
rightSelections
|
||||||
+= colorPositions(rightCharFormat, rightCursor, chunkData.changedRightPositions);
|
+= colorPositions(rightCharFormat, rightCursor, rightCharPos);
|
||||||
}
|
|
||||||
|
|
||||||
m_leftEditor->setExtraSelections(BaseTextEditorWidget::OtherSelection,
|
m_leftEditor->setExtraSelections(BaseTextEditorWidget::OtherSelection,
|
||||||
m_leftEditor->extraSelections(BaseTextEditorWidget::OtherSelection)
|
m_leftEditor->extraSelections(BaseTextEditorWidget::OtherSelection)
|
||||||
|
|||||||
@@ -81,11 +81,9 @@ struct RowData {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct ChunkData {
|
struct ChunkData {
|
||||||
ChunkData() : skippedLinesBefore(0), leftOffset(0), rightOffset(0) {}
|
ChunkData() : alwaysShown(true) {}
|
||||||
QList<RowData> rows;
|
QList<RowData> rows;
|
||||||
int skippedLinesBefore; // info for text
|
bool alwaysShown;
|
||||||
int leftOffset;
|
|
||||||
int rightOffset;
|
|
||||||
// <absolute position in the file, absolute position in the file>
|
// <absolute position in the file, absolute position in the file>
|
||||||
QMap<int, int> changedLeftPositions; // counting from the beginning of the chunk
|
QMap<int, int> changedLeftPositions; // counting from the beginning of the chunk
|
||||||
QMap<int, int> changedRightPositions; // counting from the beginning of the chunk
|
QMap<int, int> changedRightPositions; // counting from the beginning of the chunk
|
||||||
@@ -96,7 +94,6 @@ struct FileData {
|
|||||||
FileData() {}
|
FileData() {}
|
||||||
FileData(const ChunkData &chunkData) { chunks.append(chunkData); }
|
FileData(const ChunkData &chunkData) { chunks.append(chunkData); }
|
||||||
QList<ChunkData> chunks;
|
QList<ChunkData> chunks;
|
||||||
QList<int> chunkOffset;
|
|
||||||
QString text;
|
QString text;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -150,8 +147,6 @@ private:
|
|||||||
|
|
||||||
ChunkData m_originalChunkData;
|
ChunkData m_originalChunkData;
|
||||||
FileData m_contextFileData;
|
FileData m_contextFileData;
|
||||||
int m_leftSafePosHack;
|
|
||||||
int m_rightSafePosHack;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace DiffEditor
|
} // namespace DiffEditor
|
||||||
|
|||||||
@@ -3293,8 +3293,10 @@ void BaseTextEditorWidget::paintEvent(QPaintEvent *e)
|
|||||||
if ((hasMainSelection && i == context.selections.size()-1)
|
if ((hasMainSelection && i == context.selections.size()-1)
|
||||||
|| (o.format.foreground().style() == Qt::NoBrush
|
|| (o.format.foreground().style() == Qt::NoBrush
|
||||||
&& o.format.underlineStyle() != QTextCharFormat::NoUnderline
|
&& o.format.underlineStyle() != QTextCharFormat::NoUnderline
|
||||||
&& o.format.background() == Qt::NoBrush))
|
&& o.format.background() == Qt::NoBrush)) {
|
||||||
|
if (selectionVisible(block.blockNumber()))
|
||||||
prioritySelections.append(o);
|
prioritySelections.append(o);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
selections.append(o);
|
selections.append(o);
|
||||||
}
|
}
|
||||||
@@ -3484,7 +3486,6 @@ void BaseTextEditorWidget::paintEvent(QPaintEvent *e)
|
|||||||
int selectionStart = cursor.selectionStart();
|
int selectionStart = cursor.selectionStart();
|
||||||
int selectionEnd = cursor.selectionEnd();
|
int selectionEnd = cursor.selectionEnd();
|
||||||
|
|
||||||
|
|
||||||
while (block.isValid() && top <= e->rect().bottom()) {
|
while (block.isValid() && top <= e->rect().bottom()) {
|
||||||
QTextBlock nextBlock = block.next();
|
QTextBlock nextBlock = block.next();
|
||||||
QTextBlock nextVisibleBlock = nextBlock;
|
QTextBlock nextVisibleBlock = nextBlock;
|
||||||
@@ -6196,6 +6197,11 @@ int BaseTextEditorWidget::lineNumberDigits() const
|
|||||||
return digits;
|
return digits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BaseTextEditorWidget::selectionVisible(int blockNumber) const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void BaseTextEditorWidget::appendMenuActionsFromContext(QMenu *menu, const Core::Id menuContextId)
|
void BaseTextEditorWidget::appendMenuActionsFromContext(QMenu *menu, const Core::Id menuContextId)
|
||||||
{
|
{
|
||||||
Core::ActionContainer *mcontext = Core::ActionManager::actionContainer(menuContextId);
|
Core::ActionContainer *mcontext = Core::ActionManager::actionContainer(menuContextId);
|
||||||
|
|||||||
@@ -361,6 +361,7 @@ protected:
|
|||||||
virtual QString lineNumber(int blockNumber) const;
|
virtual QString lineNumber(int blockNumber) const;
|
||||||
virtual int lineNumberTopPositionOffset(int blockNumber) const;
|
virtual int lineNumberTopPositionOffset(int blockNumber) const;
|
||||||
virtual int lineNumberDigits() const;
|
virtual int lineNumberDigits() const;
|
||||||
|
virtual bool selectionVisible(int blockNumber) const;
|
||||||
|
|
||||||
static QString msgTextTooLarge(quint64 size);
|
static QString msgTextTooLarge(quint64 size);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user