DiffEditorPlugin: Introduce DiffFileInfoArray

Change-Id: I884d72e6c500e41969f379d969bcf1f46be8fd5c
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Jarek Kobus
2022-09-29 17:49:32 +02:00
parent 835b278c00
commit daa942393a
4 changed files with 8 additions and 11 deletions

View File

@@ -38,7 +38,7 @@ namespace Internal {
class ReloadInput { class ReloadInput {
public: public:
std::array<QString, SideCount> text{}; std::array<QString, SideCount> text{};
std::array<DiffFileInfo, SideCount> fileInfo{}; DiffFileInfoArray fileInfo{};
FileData::FileOperation fileOperation = FileData::ChangeFile; FileData::FileOperation fileOperation = FileData::ChangeFile;
bool binaryFiles = false; bool binaryFiles = false;
}; };

View File

@@ -11,6 +11,8 @@
#include <QMap> #include <QMap>
#include <QString> #include <QString>
#include <array>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QFutureInterfaceBase; class QFutureInterfaceBase;
QT_END_NAMESPACE QT_END_NAMESPACE
@@ -34,6 +36,8 @@ public:
PatchBehaviour patchBehaviour = PatchFile; PatchBehaviour patchBehaviour = PatchFile;
}; };
using DiffFileInfoArray = std::array<DiffFileInfo, SideCount>;
class DIFFEDITOR_EXPORT TextLineData { class DIFFEDITOR_EXPORT TextLineData {
public: public:
enum TextLineType { enum TextLineType {
@@ -98,7 +102,7 @@ public:
FileData() = default; FileData() = default;
FileData(const ChunkData &chunkData) { chunks.append(chunkData); } FileData(const ChunkData &chunkData) { chunks.append(chunkData); }
QList<ChunkData> chunks; QList<ChunkData> chunks;
std::array<DiffFileInfo, SideCount> fileInfo{}; DiffFileInfoArray fileInfo{};
FileOperation fileOperation = ChangeFile; FileOperation fileOperation = ChangeFile;
bool binaryFiles = false; bool binaryFiles = false;
bool lastChunkAtTheEndOfFile = false; bool lastChunkAtTheEndOfFile = false;

View File

@@ -274,12 +274,6 @@ void UnifiedDiffData::setLineNumber(DiffSide side, int blockNumber, int lineNumb
m_lineNumberDigits[side] = qMax(m_lineNumberDigits[side], lineNumberString.count()); m_lineNumberDigits[side] = qMax(m_lineNumberDigits[side], lineNumberString.count());
} }
void UnifiedDiffData::setFileInfo(int blockNumber, const DiffFileInfo &leftInfo,
const DiffFileInfo &rightInfo)
{
m_fileInfo[blockNumber] = {leftInfo, rightInfo};
}
void UnifiedDiffData::setChunkIndex(int startBlockNumber, int blockCount, int chunkIndex) void UnifiedDiffData::setChunkIndex(int startBlockNumber, int blockCount, int chunkIndex)
{ {
m_chunkInfo.insert(startBlockNumber, qMakePair(blockCount, chunkIndex)); m_chunkInfo.insert(startBlockNumber, qMakePair(blockCount, chunkIndex));
@@ -428,7 +422,7 @@ UnifiedDiffOutput UnifiedDiffData::diffOutput(QFutureInterface<void> &fi, int pr
for (const FileData &fileData : qAsConst(input.m_contextFileData)) { for (const FileData &fileData : qAsConst(input.m_contextFileData)) {
const QString leftFileInfo = "--- " + fileData.fileInfo[LeftSide].fileName + '\n'; const QString leftFileInfo = "--- " + fileData.fileInfo[LeftSide].fileName + '\n';
const QString rightFileInfo = "+++ " + fileData.fileInfo[RightSide].fileName + '\n'; const QString rightFileInfo = "+++ " + fileData.fileInfo[RightSide].fileName + '\n';
output.diffData.setFileInfo(blockNumber, fileData.fileInfo[LeftSide], fileData.fileInfo[RightSide]); output.diffData.m_fileInfo[blockNumber] = fileData.fileInfo;
output.foldingIndent.insert(blockNumber, 1); output.foldingIndent.insert(blockNumber, 1);
output.selections[blockNumber].append({input.m_fileLineFormat}); output.selections[blockNumber].append({input.m_fileLineFormat});
blockNumber++; blockNumber++;

View File

@@ -38,13 +38,12 @@ public:
std::array<int, SideCount> m_lineNumberDigits{1, 1}; std::array<int, SideCount> m_lineNumberDigits{1, 1};
// block number, visual line number. // block number, visual line number.
QMap<int, QPair<DiffFileInfo, DiffFileInfo>> m_fileInfo; QMap<int, DiffFileInfoArray> m_fileInfo;
// start block number, block count of a chunk, chunk index inside a file. // start block number, block count of a chunk, chunk index inside a file.
QMap<int, QPair<int, int>> m_chunkInfo; QMap<int, QPair<int, int>> m_chunkInfo;
private: private:
void setLineNumber(DiffSide side, int blockNumber, int lineNumber, int rowNumberInChunk); void setLineNumber(DiffSide side, int blockNumber, int lineNumber, int rowNumberInChunk);
void setFileInfo(int blockNumber, const DiffFileInfo &leftInfo, const DiffFileInfo &rightInfo);
void setChunkIndex(int startBlockNumber, int blockCount, int chunkIndex); void setChunkIndex(int startBlockNumber, int blockCount, int chunkIndex);
QString setChunk(const DiffEditorInput &input, const ChunkData &chunkData, QString setChunk(const DiffEditorInput &input, const ChunkData &chunkData,
bool lastChunk, int *blockNumber, DiffSelections *selections); bool lastChunk, int *blockNumber, DiffSelections *selections);