forked from qt-creator/qt-creator
Move more function into diffutils, fix calculateOriginalData.
Change-Id: Id7bbdbf7778d21cb9aa15148876db95e9228fab3 Reviewed-by: Jarek Kobus <jaroslaw.kobus@digia.com>
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
#include "diffutils.h"
|
||||
#include "differ.h"
|
||||
#include <QStringList>
|
||||
#include "texteditor/fontsettings.h"
|
||||
|
||||
namespace DiffEditor {
|
||||
namespace Internal {
|
||||
@@ -163,8 +164,9 @@ ChunkData calculateOriginalData(const QList<Diff> &leftDiffList,
|
||||
|
||||
if (leftDifference && rightDifference) {
|
||||
bool doAlign = true;
|
||||
if (line == 0 // omit alignment when first lines of equalities are empty
|
||||
&& (newLeftLines.at(0).isEmpty() || newRightLines.at(0).isEmpty())) {
|
||||
if (line == 0 // omit alignment when first lines of equalities are empty and last generated lines are not equal
|
||||
&& (newLeftLines.at(0).isEmpty() || newRightLines.at(0).isEmpty())
|
||||
&& !lastLineEqual) {
|
||||
doAlign = false;
|
||||
}
|
||||
|
||||
@@ -234,7 +236,7 @@ ChunkData calculateOriginalData(const QList<Diff> &leftDiffList,
|
||||
++leftLine;
|
||||
if (rightTextLine.textLineType == TextLineData::TextLine)
|
||||
++rightLine;
|
||||
if (equalLines.value(leftLine, -1) == rightLine)
|
||||
if (equalLines.value(leftLine, -2) == rightLine)
|
||||
row.equal = true;
|
||||
|
||||
chunkData.rows.append(row);
|
||||
@@ -347,5 +349,36 @@ FileData calculateContextData(const ChunkData &originalData, int contextLinesNum
|
||||
return fileData;
|
||||
}
|
||||
|
||||
QList<QTextEdit::ExtraSelection> colorPositions(
|
||||
const QTextCharFormat &format,
|
||||
QTextCursor &cursor,
|
||||
const QMap<int, int> &positions)
|
||||
{
|
||||
QList<QTextEdit::ExtraSelection> lineSelections;
|
||||
|
||||
cursor.setPosition(0);
|
||||
QMapIterator<int, int> itPositions(positions);
|
||||
while (itPositions.hasNext()) {
|
||||
itPositions.next();
|
||||
|
||||
cursor.setPosition(itPositions.key());
|
||||
cursor.setPosition(itPositions.value(), QTextCursor::KeepAnchor);
|
||||
|
||||
QTextEdit::ExtraSelection selection;
|
||||
selection.cursor = cursor;
|
||||
selection.format = format;
|
||||
lineSelections.append(selection);
|
||||
}
|
||||
return lineSelections;
|
||||
}
|
||||
|
||||
QTextCharFormat fullWidthFormatForTextStyle(const TextEditor::FontSettings &fontSettings,
|
||||
TextEditor::TextStyle textStyle)
|
||||
{
|
||||
QTextCharFormat format = fontSettings.toTextCharFormat(textStyle);
|
||||
format.setProperty(QTextFormat::FullWidthSelection, true);
|
||||
return format;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace DiffEditor
|
||||
|
||||
@@ -32,7 +32,12 @@
|
||||
|
||||
#include <QString>
|
||||
#include <QMap>
|
||||
#include <QTextEdit>
|
||||
|
||||
#include "diffeditorcontroller.h"
|
||||
#include "texteditor/texteditorconstants.h"
|
||||
|
||||
namespace TextEditor { class FontSettings; }
|
||||
|
||||
namespace DiffEditor {
|
||||
|
||||
@@ -89,7 +94,11 @@ ChunkData calculateOriginalData(const QList<Diff> &leftDiffList,
|
||||
const QList<Diff> &rightDiffList);
|
||||
FileData calculateContextData(const ChunkData &originalData,
|
||||
int contextLinesNumber);
|
||||
|
||||
QList<QTextEdit::ExtraSelection> colorPositions(const QTextCharFormat &format,
|
||||
QTextCursor &cursor,
|
||||
const QMap<int, int> &positions);
|
||||
QTextCharFormat fullWidthFormatForTextStyle(const TextEditor::FontSettings &fontSettings,
|
||||
TextEditor::TextStyle textStyle);
|
||||
} // namespace Internal
|
||||
} // namespace DiffEditor
|
||||
|
||||
|
||||
@@ -756,6 +756,9 @@ SideBySideDiffEditorWidget::~SideBySideDiffEditorWidget()
|
||||
|
||||
void SideBySideDiffEditorWidget::setDiffEditorGuiController(DiffEditorGuiController *controller)
|
||||
{
|
||||
if (m_guiController == controller)
|
||||
return;
|
||||
|
||||
if (m_guiController) {
|
||||
disconnect(m_controller, SIGNAL(cleared(QString)), this, SLOT(clear(QString)));
|
||||
disconnect(m_controller, SIGNAL(diffContentsChanged(QList<DiffEditorController::DiffFilesContents>,QString)),
|
||||
@@ -850,8 +853,8 @@ void SideBySideDiffEditorWidget::handleWhitespaces(const QList<Diff> &input,
|
||||
|
||||
Differ::splitDiffList(input, leftOutput, rightOutput);
|
||||
if (m_guiController && m_guiController->isIgnoreWhitespaces()) {
|
||||
QList<Diff> leftDiffList = Differ::moveWhitespaceIntoEqualities(*leftOutput);
|
||||
QList<Diff> rightDiffList = Differ::moveWhitespaceIntoEqualities(*rightOutput);
|
||||
const QList<Diff> leftDiffList = Differ::moveWhitespaceIntoEqualities(*leftOutput);
|
||||
const QList<Diff> rightDiffList = Differ::moveWhitespaceIntoEqualities(*rightOutput);
|
||||
Differ::diffBetweenEqualities(leftDiffList, rightDiffList, leftOutput, rightOutput);
|
||||
}
|
||||
}
|
||||
@@ -1034,30 +1037,7 @@ void SideBySideDiffEditorWidget::showDiff()
|
||||
m_rightEditor->updateFoldingHighlight(QPoint(-1, -1));
|
||||
}
|
||||
|
||||
QList<QTextEdit::ExtraSelection> SideBySideDiffEditorWidget::colorPositions(
|
||||
const QTextCharFormat &format,
|
||||
QTextCursor &cursor,
|
||||
const QMap<int, int> &positions) const
|
||||
{
|
||||
QList<QTextEdit::ExtraSelection> lineSelections;
|
||||
|
||||
cursor.setPosition(0);
|
||||
QMapIterator<int, int> itPositions(positions);
|
||||
while (itPositions.hasNext()) {
|
||||
itPositions.next();
|
||||
|
||||
cursor.setPosition(itPositions.key());
|
||||
cursor.setPosition(itPositions.value(), QTextCursor::KeepAnchor);
|
||||
|
||||
QTextEdit::ExtraSelection selection;
|
||||
selection.cursor = cursor;
|
||||
selection.format = format;
|
||||
lineSelections.append(selection);
|
||||
}
|
||||
return lineSelections;
|
||||
}
|
||||
|
||||
void fixPositions(QMap<int, int>::ConstIterator *it,
|
||||
static void fixPositions(QMap<int, int>::ConstIterator *it,
|
||||
const QMap<int, int>::ConstIterator &itEnd,
|
||||
int fileOffset,
|
||||
int charCounter,
|
||||
@@ -1247,14 +1227,6 @@ void SideBySideDiffEditorWidget::colorDiff(const QList<FileData> &fileDataList)
|
||||
m_rightEditor->setExtraSelections(BaseTextEditorWidget::OtherSelection, rightSelections);
|
||||
}
|
||||
|
||||
static QTextCharFormat fullWidthFormatForTextStyle(const TextEditor::FontSettings &fontSettings,
|
||||
TextEditor::TextStyle textStyle)
|
||||
{
|
||||
QTextCharFormat format = fontSettings.toTextCharFormat(textStyle);
|
||||
format.setProperty(QTextFormat::FullWidthSelection, true);
|
||||
return format;
|
||||
}
|
||||
|
||||
void SideBySideDiffEditorWidget::setFontSettings(const TextEditor::FontSettings &fontSettings)
|
||||
{
|
||||
m_leftEditor->baseTextDocument()->setFontSettings(fontSettings);
|
||||
|
||||
@@ -33,18 +33,16 @@
|
||||
#include "diffeditor_global.h"
|
||||
#include "differ.h"
|
||||
#include "diffeditorcontroller.h"
|
||||
|
||||
#include <QTextEdit>
|
||||
#include <QWidget>
|
||||
#include <QTextCharFormat>
|
||||
|
||||
namespace TextEditor { class FontSettings; }
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QSplitter;
|
||||
class QTextCharFormat;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
||||
|
||||
namespace DiffEditor {
|
||||
class DiffEditorGuiController;
|
||||
class SideDiffEditorWidget;
|
||||
@@ -100,9 +98,6 @@ private:
|
||||
void handleWhitespaces(const QList<Diff> &input,
|
||||
QList<Diff> *leftOutput,
|
||||
QList<Diff> *rightOutput) const;
|
||||
QList<QTextEdit::ExtraSelection> colorPositions(const QTextCharFormat &format,
|
||||
QTextCursor &cursor,
|
||||
const QMap<int, int> &positions) const;
|
||||
void colorDiff(const QList<Internal::FileData> &fileDataList);
|
||||
void showDiff();
|
||||
void synchronizeFoldings(SideDiffEditorWidget *source, SideDiffEditorWidget *destination);
|
||||
@@ -119,7 +114,6 @@ private:
|
||||
QList<Internal::FileData> m_contextFileData; // ultimate data to be shown, contextLinesNumber taken into account
|
||||
|
||||
bool m_foldingBlocker;
|
||||
QString m_source;
|
||||
|
||||
QTextCharFormat m_fileLineFormat;
|
||||
QTextCharFormat m_chunkLineFormat;
|
||||
|
||||
Reference in New Issue
Block a user