diff options
author | jkobus <jaroslaw.kobus@digia.com> | 2013-06-07 15:23:12 +0200 |
---|---|---|
committer | hjk <hjk121@nokiamail.com> | 2013-06-07 15:36:55 +0200 |
commit | 2ddcc0c3862bcb114b93b2bd4de6922f6b9d1ef9 (patch) | |
tree | 41f2cfb701bf3f3dc11145e04f05cd68e6834c3d | |
parent | c8b478f0bdfd30a0dfb0cf4066930e7b676a7a62 (diff) | |
download | qt-creator-2ddcc0c3862bcb114b93b2bd4de6922f6b9d1ef9.tar.gz |
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>
-rw-r--r-- | src/plugins/diffeditor/diffeditorplugin.cpp | 10 | ||||
-rw-r--r-- | src/plugins/diffeditor/diffeditorplugin.h | 4 | ||||
-rw-r--r-- | src/plugins/diffeditor/diffeditorwidget.cpp | 40 | ||||
-rw-r--r-- | src/plugins/diffeditor/diffeditorwidget.h | 4 |
4 files changed, 57 insertions, 1 deletions
diff --git a/src/plugins/diffeditor/diffeditorplugin.cpp b/src/plugins/diffeditor/diffeditorplugin.cpp index 6ca9090f03..a3a86b6d8f 100644 --- a/src/plugins/diffeditor/diffeditorplugin.cpp +++ b/src/plugins/diffeditor/diffeditorplugin.cpp @@ -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) diff --git a/src/plugins/diffeditor/diffeditorplugin.h b/src/plugins/diffeditor/diffeditorplugin.h index 8c1303d7a4..12b4b5bd1c 100644 --- a/src/plugins/diffeditor/diffeditorplugin.h +++ b/src/plugins/diffeditor/diffeditorplugin.h @@ -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; diff --git a/src/plugins/diffeditor/diffeditorwidget.cpp b/src/plugins/diffeditor/diffeditorwidget.cpp index 4bce0b3466..97616375ea 100644 --- a/src/plugins/diffeditor/diffeditorwidget.cpp +++ b/src/plugins/diffeditor/diffeditorwidget.cpp @@ -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" diff --git a/src/plugins/diffeditor/diffeditorwidget.h b/src/plugins/diffeditor/diffeditorwidget.h index 8e4973c7f6..28affe26c8 100644 --- a/src/plugins/diffeditor/diffeditorwidget.h +++ b/src/plugins/diffeditor/diffeditorwidget.h @@ -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); |