forked from qt-creator/qt-creator
Fix wrong diff output with span lines
Task-number: QTCREATORBUG-9494 Change-Id: Ica26e1448b1997e102648be58128f1be00c4905e Reviewed-by: hjk <hjk121@nokiamail.com> Reviewed-by: Christian Stenger <christian.stenger@digia.com>
This commit is contained in:
@@ -172,4 +172,14 @@ QString DiffEditorPlugin::getFileContents(const QString &fileName, QTextCodec *c
|
||||
} // namespace Internal
|
||||
} // namespace DiffEditor
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
|
||||
void DiffEditor::Internal::DiffEditorPlugin::testAssemblyRows()
|
||||
{
|
||||
DiffEditorWidget widget;
|
||||
widget.testAssemblyRows();
|
||||
}
|
||||
|
||||
#endif // WITH_TESTS
|
||||
|
||||
Q_EXPORT_PLUGIN(DiffEditor::Internal::DiffEditorPlugin)
|
||||
|
@@ -65,6 +65,10 @@ public:
|
||||
private slots:
|
||||
void diff();
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
void testAssemblyRows();
|
||||
#endif // WITH_TESTS
|
||||
|
||||
private:
|
||||
QString getFileContents(const QString &fileName, QTextCodec *codec) const;
|
||||
|
||||
|
@@ -775,8 +775,10 @@ QList<TextLineData> DiffEditorWidget::assemblyRows(const QStringList &lines,
|
||||
{
|
||||
QList<TextLineData> data;
|
||||
|
||||
int previousSpanOffset = 0;
|
||||
int spanOffset = 0;
|
||||
int pos = 0;
|
||||
bool usePreviousSpanOffsetForStartPosition = false;
|
||||
QMap<int, int>::ConstIterator changedIt = changedPositions.constBegin();
|
||||
QMap<int, int>::ConstIterator changedEnd = changedPositions.constEnd();
|
||||
const int lineCount = lines.count();
|
||||
@@ -794,7 +796,17 @@ QList<TextLineData> DiffEditorWidget::assemblyRows(const QStringList &lines,
|
||||
if (changedIt.key() >= pos)
|
||||
break;
|
||||
|
||||
const int startPos = changedIt.key() + spanOffset;
|
||||
if (changedIt.value() >= pos) {
|
||||
usePreviousSpanOffsetForStartPosition = true;
|
||||
previousSpanOffset = spanOffset;
|
||||
break;
|
||||
}
|
||||
|
||||
const int startSpanOffset = usePreviousSpanOffsetForStartPosition
|
||||
? previousSpanOffset : spanOffset;
|
||||
usePreviousSpanOffsetForStartPosition = false;
|
||||
|
||||
const int startPos = changedIt.key() + startSpanOffset;
|
||||
const int endPos = changedIt.value() + spanOffset;
|
||||
if (outputChangedPositions)
|
||||
outputChangedPositions->insert(startPos, endPos);
|
||||
@@ -1550,4 +1562,30 @@ void DiffEditorWidget::synchronizeFoldings(DiffViewEditorWidget *source, DiffVie
|
||||
|
||||
} // namespace DiffEditor
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
#include <QTest>
|
||||
|
||||
void DiffEditor::DiffEditorWidget::testAssemblyRows()
|
||||
{
|
||||
QStringList lines;
|
||||
lines << QLatin1String("abcd efgh"); // line 0
|
||||
lines << QLatin1String("ijkl mnop"); // line 1
|
||||
|
||||
QMap<int, int> lineSpans;
|
||||
lineSpans[1] = 6; // before line 1 insert 6 span lines
|
||||
|
||||
QMap<int, int> changedPositions;
|
||||
changedPositions[5] = 14; // changed text from position 5 to position 14, occupy 9 characters: "efgh\nijkl"
|
||||
|
||||
QMap<int, int> expectedChangedPositions;
|
||||
expectedChangedPositions[5] = 20; // "efgh\n[\n\n\n\n\n\n]ijkl" - [\n] means inserted span
|
||||
|
||||
QMap<int, int> outputChangedPositions;
|
||||
|
||||
assemblyRows(lines, lineSpans, changedPositions, &outputChangedPositions);
|
||||
QVERIFY(outputChangedPositions == expectedChangedPositions);
|
||||
}
|
||||
|
||||
#endif // WITH_TESTS
|
||||
|
||||
#include "diffeditorwidget.moc"
|
||||
|
@@ -83,6 +83,10 @@ public:
|
||||
void setDiff(const QList<DiffFilesContents> &diffFileList, const QString &workingDirectory = QString());
|
||||
QTextCodec *codec() const;
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
void testAssemblyRows();
|
||||
#endif // WITH_TESTS
|
||||
|
||||
public slots:
|
||||
void setContextLinesNumber(int lines);
|
||||
void setIgnoreWhitespaces(bool ignore);
|
||||
|
Reference in New Issue
Block a user