forked from qt-creator/qt-creator
Small refactor.
Change-Id: I8bdf3830e230b5db3d6041fae0d22c05cfc047d8 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
@@ -181,6 +181,20 @@ static void handleLine(const QStringList &newLines,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void handleDifference(const QString &text,
|
||||||
|
QStringList *lines,
|
||||||
|
QMap<int, int> *changedPositions,
|
||||||
|
int *lineNumber,
|
||||||
|
int *charNumber)
|
||||||
|
{
|
||||||
|
const int oldPosition = *lineNumber + *charNumber;
|
||||||
|
const QStringList newLeftLines = text.split(QLatin1Char('\n'));
|
||||||
|
for (int line = 0; line < newLeftLines.count(); ++line)
|
||||||
|
handleLine(newLeftLines, line, lines, lineNumber, charNumber);
|
||||||
|
const int newPosition = *lineNumber + *charNumber;
|
||||||
|
changedPositions->insert(oldPosition, newPosition);
|
||||||
|
}
|
||||||
|
|
||||||
static bool lastLinesEqual(const QStringList &leftLines,
|
static bool lastLinesEqual(const QStringList &leftLines,
|
||||||
const QStringList &rightLines)
|
const QStringList &rightLines)
|
||||||
{
|
{
|
||||||
@@ -237,23 +251,13 @@ static ChunkData calculateOriginalData(const QList<Diff> &leftDiffList,
|
|||||||
|
|
||||||
if (leftDiff.command == Diff::Delete) {
|
if (leftDiff.command == Diff::Delete) {
|
||||||
// process delete
|
// process delete
|
||||||
const int oldPosition = leftCharNumber + leftLineNumber;
|
handleDifference(leftDiff.text, &leftLines, &leftChangedPositions, &leftLineNumber, &leftCharNumber);
|
||||||
const QStringList newLeftLines = leftDiff.text.split(QLatin1Char('\n'));
|
|
||||||
for (int line = 0; line < newLeftLines.count(); line++)
|
|
||||||
handleLine(newLeftLines, line, &leftLines, &leftLineNumber, &leftCharNumber);
|
|
||||||
const int newPosition = leftCharNumber + leftLineNumber;
|
|
||||||
leftChangedPositions.insert(oldPosition, newPosition);
|
|
||||||
lastLineEqual = lastLinesEqual(leftLines, rightLines);
|
lastLineEqual = lastLinesEqual(leftLines, rightLines);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (rightDiff.command == Diff::Insert) {
|
if (rightDiff.command == Diff::Insert) {
|
||||||
// process insert
|
// process insert
|
||||||
const int oldPosition = rightCharNumber + rightLineNumber;
|
handleDifference(rightDiff.text, &rightLines, &rightChangedPositions, &rightLineNumber, &rightCharNumber);
|
||||||
const QStringList newRightLines = rightDiff.text.split(QLatin1Char('\n'));
|
|
||||||
for (int line = 0; line < newRightLines.count(); line++)
|
|
||||||
handleLine(newRightLines, line, &rightLines, &rightLineNumber, &rightCharNumber);
|
|
||||||
const int newPosition = rightCharNumber + rightLineNumber;
|
|
||||||
rightChangedPositions.insert(oldPosition, newPosition);
|
|
||||||
lastLineEqual = lastLinesEqual(leftLines, rightLines);
|
lastLineEqual = lastLinesEqual(leftLines, rightLines);
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user