forked from qt-creator/qt-creator
DiffEditor: Use DiffSide enum inside RowData
Change-Id: I5511e443e2f76a1dab5cc78eec5faec04ee31bcc Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -58,8 +58,8 @@ DiffEditorController *DiffEditorDocument::controller() const
|
|||||||
|
|
||||||
static void appendRow(ChunkData *chunk, const RowData &row)
|
static void appendRow(ChunkData *chunk, const RowData &row)
|
||||||
{
|
{
|
||||||
const bool isSeparator = row.leftLine.textLineType == TextLineData::Separator
|
const bool isSeparator = row.line[LeftSide].textLineType == TextLineData::Separator
|
||||||
&& row.rightLine.textLineType == TextLineData::Separator;
|
&& row.line[RightSide].textLineType == TextLineData::Separator;
|
||||||
if (!isSeparator)
|
if (!isSeparator)
|
||||||
chunk->rows.append(row);
|
chunk->rows.append(row);
|
||||||
}
|
}
|
||||||
@@ -83,30 +83,30 @@ ChunkData DiffEditorDocument::filterChunk(const ChunkData &data,
|
|||||||
} else if (isLeftSelected) {
|
} else if (isLeftSelected) {
|
||||||
RowData newRow = row;
|
RowData newRow = row;
|
||||||
|
|
||||||
row.rightLine = TextLineData(TextLineData::Separator);
|
row.line[RightSide] = TextLineData(TextLineData::Separator);
|
||||||
appendRow(&chunk, row);
|
appendRow(&chunk, row);
|
||||||
|
|
||||||
if (revert) {
|
if (revert) {
|
||||||
newRow.leftLine = newRow.rightLine;
|
newRow.line[LeftSide] = newRow.line[RightSide];
|
||||||
newRow.equal = true;
|
newRow.equal = true;
|
||||||
appendRow(&chunk, newRow);
|
appendRow(&chunk, newRow);
|
||||||
}
|
}
|
||||||
} else { // isRightSelected
|
} else { // isRightSelected
|
||||||
if (!revert) {
|
if (!revert) {
|
||||||
RowData newRow = row;
|
RowData newRow = row;
|
||||||
newRow.rightLine = newRow.leftLine;
|
newRow.line[RightSide] = newRow.line[LeftSide];
|
||||||
newRow.equal = true;
|
newRow.equal = true;
|
||||||
appendRow(&chunk, newRow);
|
appendRow(&chunk, newRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
row.leftLine = TextLineData(TextLineData::Separator);
|
row.line[LeftSide] = TextLineData(TextLineData::Separator);
|
||||||
appendRow(&chunk, row);
|
appendRow(&chunk, row);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (revert)
|
if (revert)
|
||||||
row.leftLine = row.rightLine;
|
row.line[LeftSide] = row.line[RightSide];
|
||||||
else
|
else
|
||||||
row.rightLine = row.leftLine;
|
row.line[RightSide] = row.line[LeftSide];
|
||||||
row.equal = true;
|
row.equal = true;
|
||||||
appendRow(&chunk, row);
|
appendRow(&chunk, row);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -851,10 +851,10 @@ void DiffEditor::Internal::DiffEditorPlugin::testMakePatch()
|
|||||||
const RowData &sourceRowData = sourceChunk.rows.at(k);
|
const RowData &sourceRowData = sourceChunk.rows.at(k);
|
||||||
const RowData &resultRowData = resultChunkData.rows.at(k);
|
const RowData &resultRowData = resultChunkData.rows.at(k);
|
||||||
QCOMPARE(resultRowData.equal, sourceRowData.equal);
|
QCOMPARE(resultRowData.equal, sourceRowData.equal);
|
||||||
QCOMPARE(resultRowData.leftLine.text, sourceRowData.leftLine.text);
|
QCOMPARE(resultRowData.line[LeftSide].text, sourceRowData.line[LeftSide].text);
|
||||||
QCOMPARE(resultRowData.leftLine.textLineType, sourceRowData.leftLine.textLineType);
|
QCOMPARE(resultRowData.line[LeftSide].textLineType, sourceRowData.line[LeftSide].textLineType);
|
||||||
QCOMPARE(resultRowData.rightLine.text, sourceRowData.rightLine.text);
|
QCOMPARE(resultRowData.line[RightSide].text, sourceRowData.line[RightSide].text);
|
||||||
QCOMPARE(resultRowData.rightLine.textLineType, sourceRowData.rightLine.textLineType);
|
QCOMPARE(resultRowData.line[RightSide].textLineType, sourceRowData.line[RightSide].textLineType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1429,10 +1429,10 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch()
|
|||||||
const RowData &origRowData = origChunkData.rows.at(k);
|
const RowData &origRowData = origChunkData.rows.at(k);
|
||||||
const RowData &resultRowData = resultChunkData.rows.at(k);
|
const RowData &resultRowData = resultChunkData.rows.at(k);
|
||||||
QCOMPARE(resultRowData.equal, origRowData.equal);
|
QCOMPARE(resultRowData.equal, origRowData.equal);
|
||||||
QCOMPARE(resultRowData.leftLine.text, origRowData.leftLine.text);
|
QCOMPARE(resultRowData.line[LeftSide].text, origRowData.line[LeftSide].text);
|
||||||
QCOMPARE(resultRowData.leftLine.textLineType, origRowData.leftLine.textLineType);
|
QCOMPARE(resultRowData.line[LeftSide].textLineType, origRowData.line[LeftSide].textLineType);
|
||||||
QCOMPARE(resultRowData.rightLine.text, origRowData.rightLine.text);
|
QCOMPARE(resultRowData.line[RightSide].text, origRowData.line[RightSide].text);
|
||||||
QCOMPARE(resultRowData.rightLine.textLineType, origRowData.rightLine.textLineType);
|
QCOMPARE(resultRowData.line[RightSide].textLineType, origRowData.line[RightSide].textLineType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1457,10 +1457,10 @@ void DiffEditor::Internal::DiffEditorPlugin::testFilterPatch_data()
|
|||||||
auto appendRow = [](ChunkData *chunk, const QString &left, const QString &right) {
|
auto appendRow = [](ChunkData *chunk, const QString &left, const QString &right) {
|
||||||
RowData row;
|
RowData row;
|
||||||
row.equal = (left == right);
|
row.equal = (left == right);
|
||||||
row.leftLine.text = left;
|
row.line[LeftSide].text = left;
|
||||||
row.leftLine.textLineType = left.isEmpty() ? TextLineData::Separator : TextLineData::TextLine;
|
row.line[LeftSide].textLineType = left.isEmpty() ? TextLineData::Separator : TextLineData::TextLine;
|
||||||
row.rightLine.text = right;
|
row.line[RightSide].text = right;
|
||||||
row.rightLine.textLineType = right.isEmpty() ? TextLineData::Separator : TextLineData::TextLine;
|
row.line[RightSide].textLineType = right.isEmpty() ? TextLineData::Separator : TextLineData::TextLine;
|
||||||
chunk->rows.append(row);
|
chunk->rows.append(row);
|
||||||
};
|
};
|
||||||
ChunkData chunk;
|
ChunkData chunk;
|
||||||
@@ -1664,8 +1664,8 @@ void DiffEditor::Internal::DiffEditorPlugin::testFilterPatch()
|
|||||||
const ChunkData result = DiffEditorDocument::filterChunk(chunk, selection, revert);
|
const ChunkData result = DiffEditorDocument::filterChunk(chunk, selection, revert);
|
||||||
QCOMPARE(result.rows.size(), rows.size());
|
QCOMPARE(result.rows.size(), rows.size());
|
||||||
for (int i = 0; i < rows.size(); ++i) {
|
for (int i = 0; i < rows.size(); ++i) {
|
||||||
QCOMPARE(result.rows.at(i).leftLine.text, rows.at(i).first);
|
QCOMPARE(result.rows.at(i).line[LeftSide].text, rows.at(i).first);
|
||||||
QCOMPARE(result.rows.at(i).rightLine.text, rows.at(i).second);
|
QCOMPARE(result.rows.at(i).line[RightSide].text, rows.at(i).second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -294,9 +294,9 @@ FileData DiffUtils::calculateContextData(const ChunkData &originalData, int cont
|
|||||||
break;
|
break;
|
||||||
RowData rowData = originalData.rows.at(i);
|
RowData rowData = originalData.rows.at(i);
|
||||||
chunkData.rows.append(rowData);
|
chunkData.rows.append(rowData);
|
||||||
if (rowData.leftLine.textLineType == TextLineData::TextLine)
|
if (rowData.line[LeftSide].textLineType == TextLineData::TextLine)
|
||||||
++leftLineNumber;
|
++leftLineNumber;
|
||||||
if (rowData.rightLine.textLineType == TextLineData::TextLine)
|
if (rowData.line[RightSide].textLineType == TextLineData::TextLine)
|
||||||
++rightLineNumber;
|
++rightLineNumber;
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
@@ -351,15 +351,15 @@ QString DiffUtils::makePatch(const ChunkData &chunkData,
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
for (i = rowCount; i > 0; i--) {
|
for (i = rowCount; i > 0; i--) {
|
||||||
const RowData &rowData = chunkData.rows.at(i - 1);
|
const RowData &rowData = chunkData.rows.at(i - 1);
|
||||||
if (rowData.leftLine.textLineType != TextLineData::Separator
|
if (rowData.line[LeftSide].textLineType != TextLineData::Separator
|
||||||
|| rowData.rightLine.textLineType != TextLineData::TextLine)
|
|| rowData.line[RightSide].textLineType != TextLineData::TextLine)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
const int leftSeparator = i;
|
const int leftSeparator = i;
|
||||||
for (i = rowCount; i > 0; i--) {
|
for (i = rowCount; i > 0; i--) {
|
||||||
const RowData &rowData = chunkData.rows.at(i - 1);
|
const RowData &rowData = chunkData.rows.at(i - 1);
|
||||||
if (rowData.rightLine.textLineType != TextLineData::Separator
|
if (rowData.line[RightSide].textLineType != TextLineData::Separator
|
||||||
|| rowData.leftLine.textLineType != TextLineData::TextLine)
|
|| rowData.line[LeftSide].textLineType != TextLineData::TextLine)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
const int rightSeparator = i;
|
const int rightSeparator = i;
|
||||||
@@ -409,7 +409,7 @@ QString DiffUtils::makePatch(const ChunkData &chunkData,
|
|||||||
}
|
}
|
||||||
if (i < chunkData.rows.size()) {
|
if (i < chunkData.rows.size()) {
|
||||||
const QString line = makePatchLine(' ',
|
const QString line = makePatchLine(' ',
|
||||||
rowData.rightLine.text,
|
rowData.line[RightSide].text,
|
||||||
lastChunk,
|
lastChunk,
|
||||||
i == chunkData.rows.size() - 1);
|
i == chunkData.rows.size() - 1);
|
||||||
|
|
||||||
@@ -421,10 +421,10 @@ QString DiffUtils::makePatch(const ChunkData &chunkData,
|
|||||||
diffText += line;
|
diffText += line;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (rowData.leftLine.textLineType == TextLineData::TextLine)
|
if (rowData.line[LeftSide].textLineType == TextLineData::TextLine)
|
||||||
leftBuffer.append(rowData.leftLine);
|
leftBuffer.append(rowData.line[LeftSide]);
|
||||||
if (rowData.rightLine.textLineType == TextLineData::TextLine)
|
if (rowData.line[RightSide].textLineType == TextLineData::TextLine)
|
||||||
rightBuffer.append(rowData.rightLine);
|
rightBuffer.append(rowData.line[RightSide]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,11 +64,10 @@ class DIFFEDITOR_EXPORT RowData {
|
|||||||
public:
|
public:
|
||||||
RowData() = default;
|
RowData() = default;
|
||||||
RowData(const TextLineData &l)
|
RowData(const TextLineData &l)
|
||||||
: leftLine(l), rightLine(l), equal(true) {}
|
: line({l, l}), equal(true) {}
|
||||||
RowData(const TextLineData &l, const TextLineData &r)
|
RowData(const TextLineData &l, const TextLineData &r)
|
||||||
: leftLine(l), rightLine(r) {}
|
: line({l, r}) {}
|
||||||
TextLineData leftLine;
|
std::array<TextLineData, SideCount> line{};
|
||||||
TextLineData rightLine;
|
|
||||||
bool equal = false;
|
bool equal = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -933,8 +933,8 @@ void SideBySideDiffEditorWidget::showDiff()
|
|||||||
m_rightEditor->setChunkIndex(blockNumber, chunkData.rows.count(), j);
|
m_rightEditor->setChunkIndex(blockNumber, chunkData.rows.count(), j);
|
||||||
|
|
||||||
for (const RowData &rowData : chunkData.rows) {
|
for (const RowData &rowData : chunkData.rows) {
|
||||||
TextLineData leftLineData = rowData.leftLine;
|
TextLineData leftLineData = rowData.line[LeftSide];
|
||||||
TextLineData rightLineData = rowData.rightLine;
|
TextLineData rightLineData = rowData.line[RightSide];
|
||||||
if (leftLineData.textLineType == TextLineData::TextLine) {
|
if (leftLineData.textLineType == TextLineData::TextLine) {
|
||||||
leftText += leftLineData.text;
|
leftText += leftLineData.text;
|
||||||
lastLeftLineNumber = leftLineNumber;
|
lastLeftLineNumber = leftLineNumber;
|
||||||
@@ -953,11 +953,11 @@ void SideBySideDiffEditorWidget::showDiff()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!rowData.equal) {
|
if (!rowData.equal) {
|
||||||
if (rowData.leftLine.textLineType == TextLineData::TextLine)
|
if (rowData.line[LeftSide].textLineType == TextLineData::TextLine)
|
||||||
leftFormats[blockNumber].append(DiffSelection(&m_controller.m_leftLineFormat));
|
leftFormats[blockNumber].append(DiffSelection(&m_controller.m_leftLineFormat));
|
||||||
else
|
else
|
||||||
leftFormats[blockNumber].append(DiffSelection(&m_spanLineFormat));
|
leftFormats[blockNumber].append(DiffSelection(&m_spanLineFormat));
|
||||||
if (rowData.rightLine.textLineType == TextLineData::TextLine)
|
if (rowData.line[RightSide].textLineType == TextLineData::TextLine)
|
||||||
rightFormats[blockNumber].append(DiffSelection(&m_controller.m_rightLineFormat));
|
rightFormats[blockNumber].append(DiffSelection(&m_controller.m_rightLineFormat));
|
||||||
else
|
else
|
||||||
rightFormats[blockNumber].append(DiffSelection(&m_spanLineFormat));
|
rightFormats[blockNumber].append(DiffSelection(&m_spanLineFormat));
|
||||||
@@ -1064,9 +1064,9 @@ void SideBySideDiffEditorWidget::slotLeftJumpToOriginalFileRequested(
|
|||||||
|
|
||||||
for (int j = 0; j < chunkData.rows.count(); j++) {
|
for (int j = 0; j < chunkData.rows.count(); j++) {
|
||||||
const RowData rowData = chunkData.rows.at(j);
|
const RowData rowData = chunkData.rows.at(j);
|
||||||
if (rowData.leftLine.textLineType == TextLineData::TextLine)
|
if (rowData.line[LeftSide].textLineType == TextLineData::TextLine)
|
||||||
leftLineNumber++;
|
leftLineNumber++;
|
||||||
if (rowData.rightLine.textLineType == TextLineData::TextLine)
|
if (rowData.line[RightSide].textLineType == TextLineData::TextLine)
|
||||||
rightLineNumber++;
|
rightLineNumber++;
|
||||||
if (leftLineNumber == lineNumber) {
|
if (leftLineNumber == lineNumber) {
|
||||||
int colNr = rowData.equal ? columnNumber : 0;
|
int colNr = rowData.equal ? columnNumber : 0;
|
||||||
|
|||||||
@@ -419,7 +419,7 @@ QString UnifiedDiffData::setChunk(const DiffEditorInput &input, const ChunkData
|
|||||||
}
|
}
|
||||||
if (i < chunkData.rows.count()) {
|
if (i < chunkData.rows.count()) {
|
||||||
const QString line = DiffUtils::makePatchLine(' ',
|
const QString line = DiffUtils::makePatchLine(' ',
|
||||||
rowData.rightLine.text,
|
rowData.line[RightSide].text,
|
||||||
lastChunk,
|
lastChunk,
|
||||||
i == chunkData.rows.count() - 1);
|
i == chunkData.rows.count() - 1);
|
||||||
|
|
||||||
@@ -438,12 +438,12 @@ QString UnifiedDiffData::setChunk(const DiffEditorInput &input, const ChunkData
|
|||||||
charCount += line.count();
|
charCount += line.count();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (rowData.leftLine.textLineType == TextLineData::TextLine) {
|
if (rowData.line[LeftSide].textLineType == TextLineData::TextLine) {
|
||||||
leftBuffer.append(rowData.leftLine);
|
leftBuffer.append(rowData.line[LeftSide]);
|
||||||
leftRowsBuffer.append(i);
|
leftRowsBuffer.append(i);
|
||||||
}
|
}
|
||||||
if (rowData.rightLine.textLineType == TextLineData::TextLine) {
|
if (rowData.line[RightSide].textLineType == TextLineData::TextLine) {
|
||||||
rightBuffer.append(rowData.rightLine);
|
rightBuffer.append(rowData.line[RightSide]);
|
||||||
rightRowsBuffer.append(i);
|
rightRowsBuffer.append(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -692,9 +692,9 @@ void UnifiedDiffEditorWidget::jumpToOriginalFile(const QTextCursor &cursor)
|
|||||||
int newRightLineNumber = chunkData.startingLineNumber[RightSide];
|
int newRightLineNumber = chunkData.startingLineNumber[RightSide];
|
||||||
|
|
||||||
for (const RowData &rowData : chunkData.rows) {
|
for (const RowData &rowData : chunkData.rows) {
|
||||||
if (rowData.leftLine.textLineType == TextLineData::TextLine)
|
if (rowData.line[LeftSide].textLineType == TextLineData::TextLine)
|
||||||
newLeftLineNumber++;
|
newLeftLineNumber++;
|
||||||
if (rowData.rightLine.textLineType == TextLineData::TextLine)
|
if (rowData.line[RightSide].textLineType == TextLineData::TextLine)
|
||||||
newRightLineNumber++;
|
newRightLineNumber++;
|
||||||
if (newLeftLineNumber == leftLineNumber) {
|
if (newLeftLineNumber == leftLineNumber) {
|
||||||
m_controller.jumpToOriginalFile(leftFileName, newRightLineNumber, 0);
|
m_controller.jumpToOriginalFile(leftFileName, newRightLineNumber, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user