summaryrefslogtreecommitdiff
path: root/src/plugins/diffeditor/diffeditorwidget.cpp
diff options
context:
space:
mode:
authorjkobus <jaroslaw.kobus@digia.com>2014-01-15 09:50:23 +0100
committerJarek Kobus <jaroslaw.kobus@digia.com>2014-01-16 10:21:55 +0100
commit3b2cb038cde2c290ddd1e87f7eed7f910458c5b4 (patch)
tree1a52c3513de4ffb62d52bcda618987208f0213a4 /src/plugins/diffeditor/diffeditorwidget.cpp
parentbdbf60876fa1b46bb5dd8785f165c0167c3d2c19 (diff)
downloadqt-creator-3b2cb038cde2c290ddd1e87f7eed7f910458c5b4.tar.gz
Fix display of inserted lines by the end of file
Task-number: QTCREATORBUG-11281 Change-Id: I2d84584a850cf159dd0724f79bbc967848b3047b Reviewed-by: Jarek Kobus <jaroslaw.kobus@digia.com>
Diffstat (limited to 'src/plugins/diffeditor/diffeditorwidget.cpp')
-rw-r--r--src/plugins/diffeditor/diffeditorwidget.cpp23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/plugins/diffeditor/diffeditorwidget.cpp b/src/plugins/diffeditor/diffeditorwidget.cpp
index 18284e8414..7162e58bb6 100644
--- a/src/plugins/diffeditor/diffeditorwidget.cpp
+++ b/src/plugins/diffeditor/diffeditorwidget.cpp
@@ -916,6 +916,9 @@ bool DiffEditorWidget::isWhitespace(const Diff &diff) const
bool DiffEditorWidget::isEqual(const QList<Diff> &diffList, int diffNumber) const
{
+ if (diffNumber == diffList.count())
+ return true;
+
const Diff &diff = diffList.at(diffNumber);
if (diff.command == Diff::Equal)
return true;
@@ -1035,8 +1038,10 @@ ChunkData DiffEditorWidget::calculateOriginalData(const QList<Diff> &diffList) c
bool lastLeftLineEqual = true;
bool lastRightLineEqual = true;
- for (int i = 0; i < diffList.count(); i++) {
- Diff diff = diffList.at(i);
+ for (int i = 0; i <= diffList.count(); i++) {
+ Diff diff = i < diffList.count()
+ ? diffList.at(i)
+ : Diff(Diff::Equal, QLatin1String("")); // dummy, ensure we process to the end even when diffList doesn't end with equality
const QStringList lines = diff.text.split(QLatin1Char('\n'));
@@ -1052,14 +1057,14 @@ ChunkData DiffEditorWidget::calculateOriginalData(const QList<Diff> &diffList) c
for (int j = 0; j < lines.count(); j++) {
const QString line = lines.at(j);
- if (j > 0) {
- if (diff.command == Diff::Equal) {
- if (lastLeftLineEqual && lastRightLineEqual) {
- leftEqualLines.append(currentLeftLine);
- rightEqualLines.append(currentRightLine);
- }
+ if (j > 0 || i == diffList.count()) {
+ if (diff.command == Diff::Equal && lastLeftLineEqual && lastRightLineEqual) {
+ leftEqualLines.append(currentLeftLine);
+ rightEqualLines.append(currentRightLine);
}
+ }
+ if (j > 0) {
if (diff.command != Diff::Insert) {
currentLeftLine++;
currentLeftLineOffset++;
@@ -1083,7 +1088,7 @@ ChunkData DiffEditorWidget::calculateOriginalData(const QList<Diff> &diffList) c
rightLines.last() += line;
currentRightPos += line.count();
} else if (diff.command == Diff::Equal) {
- if ((line.count() || (j && j < lines.count() - 1)) && // don't treat empty ending line as a line to be aligned unless a line is a one char '/n' only.
+ if ((line.count() || (j && j < lines.count() - 1) || (i == diffList.count())) && // don't treat empty ending line as a line to be aligned unless a line is a one char '\n' only or it's the last line.
currentLeftLine != lastAlignedLeftLine &&
currentRightLine != lastAlignedRightLine) {
// apply line spans before the current lines