{
swap(begin[index1], begin[index2]);
swap(end[index1], end[index2]);
- swap(dbegin[index1], dbegin[index2]);
- swap(dend[index1], dend[index2]);
swap(blank[index1], blank[index2]);
}
int DiffList::LineRelDiff(int nLine, int nDiff) const
{
const DIFFRANGE * dfi = DiffRangeAt(nDiff);
- if (static_cast<int>(nLine) < dfi->dbegin[0])
+ if (static_cast<int>(nLine) < dfi->dbegin)
return -1;
- else if (static_cast<int>(nLine) > dfi->dend[0])
+ else if (static_cast<int>(nLine) > dfi->dend)
return 1;
else
return 0;
bool DiffList::LineInDiff(int nLine, int nDiff) const
{
const DIFFRANGE * dfi = DiffRangeAt(nDiff);
- if (static_cast<int>(nLine) >= dfi->dbegin[0] && static_cast<int>(nLine) <= dfi->dend[0])
+ if (static_cast<int>(nLine) >= dfi->dbegin && static_cast<int>(nLine) <= dfi->dend)
return true;
else
return false;
return -1;
// First check line is not before first or after last diff
- if (static_cast<int>(nLine) < DiffRangeAt(0)->dbegin[0])
+ if (static_cast<int>(nLine) < DiffRangeAt(0)->dbegin)
return -1;
- if (static_cast<int>(nLine) > DiffRangeAt(nDiffCount-1)->dend[0])
+ if (static_cast<int>(nLine) > DiffRangeAt(nDiffCount-1)->dend)
return -1;
// Use binary search to search for a diff.
const int size = (int) m_diffs.size();
for (int i = (int) size - 1; i >= 0 ; i--)
{
- if ((int)DiffRangeAt(i)->dend[0] <= nLine)
+ if ((int)DiffRangeAt(i)->dend <= nLine)
{
numDiff = i;
break;
const int nDiffCount = (int) m_diffs.size();
for (int i = 0; i < nDiffCount; i++)
{
- if ((int)DiffRangeAt(i)->dbegin[0] >= nLine)
+ if ((int)DiffRangeAt(i)->dbegin >= nLine)
{
numDiff = i;
break;
for (int i = size - 1; i >= 0 ; i--)
{
const DIFFRANGE * dfi = DiffRangeAt(i);
- if (dfi->op != OP_TRIVIAL && dfi->dend[0] <= static_cast<int>(nLine))
+ if (dfi->op != OP_TRIVIAL && dfi->dend <= static_cast<int>(nLine))
{
nDiff = i;
break;
for (size_t i = 0; i < nDiffCount; i++)
{
const DIFFRANGE * dfi = DiffRangeAt(i);
- if (dfi->op != OP_TRIVIAL && dfi->dbegin[0] >= static_cast<int>(nLine))
+ if (dfi->op != OP_TRIVIAL && dfi->dbegin >= static_cast<int>(nLine))
{
nDiff = i;
break;
switch (nDiffType)
{
case THREEWAYDIFFTYPE_LEFTMIDDLE:
- if (dfi->op != OP_TRIVIAL && dfi->op != OP_3RDONLY && dfi->dend[0] <= static_cast<int>(nLine))
+ if (dfi->op != OP_TRIVIAL && dfi->op != OP_3RDONLY && dfi->dend <= static_cast<int>(nLine))
return i;
break;
case THREEWAYDIFFTYPE_LEFTRIGHT:
- if (dfi->op != OP_TRIVIAL && dfi->op != OP_2NDONLY && dfi->dend[0] <= static_cast<int>(nLine))
+ if (dfi->op != OP_TRIVIAL && dfi->op != OP_2NDONLY && dfi->dend <= static_cast<int>(nLine))
return i;
break;
case THREEWAYDIFFTYPE_MIDDLERIGHT:
- if (dfi->op != OP_TRIVIAL && dfi->op != OP_1STONLY && dfi->dend[0] <= static_cast<int>(nLine))
+ if (dfi->op != OP_TRIVIAL && dfi->op != OP_1STONLY && dfi->dend <= static_cast<int>(nLine))
return i;
break;
case THREEWAYDIFFTYPE_LEFTONLY:
- if (dfi->op == OP_1STONLY && dfi->dend[0] <= static_cast<int>(nLine))
+ if (dfi->op == OP_1STONLY && dfi->dend <= static_cast<int>(nLine))
return i;
break;
case THREEWAYDIFFTYPE_MIDDLEONLY:
- if (dfi->op == OP_2NDONLY && dfi->dend[0] <= static_cast<int>(nLine))
+ if (dfi->op == OP_2NDONLY && dfi->dend <= static_cast<int>(nLine))
return i;
break;
case THREEWAYDIFFTYPE_RIGHTONLY:
- if (dfi->op == OP_3RDONLY && dfi->dend[0] <= static_cast<int>(nLine))
+ if (dfi->op == OP_3RDONLY && dfi->dend <= static_cast<int>(nLine))
return i;
break;
case THREEWAYDIFFTYPE_CONFLICT:
- if (dfi->op == OP_DIFF && dfi->dend[0] <= nLine)
+ if (dfi->op == OP_DIFF && dfi->dend <= nLine)
return i;
break;
}
switch (nDiffType)
{
case THREEWAYDIFFTYPE_LEFTMIDDLE:
- if (dfi->op != OP_TRIVIAL && dfi->op != OP_3RDONLY && dfi->dbegin[0] >= static_cast<int>(nLine))
+ if (dfi->op != OP_TRIVIAL && dfi->op != OP_3RDONLY && dfi->dbegin >= static_cast<int>(nLine))
return i;
break;
case THREEWAYDIFFTYPE_LEFTRIGHT:
- if (dfi->op != OP_TRIVIAL && dfi->op != OP_2NDONLY && dfi->dbegin[0] >= static_cast<int>(nLine))
+ if (dfi->op != OP_TRIVIAL && dfi->op != OP_2NDONLY && dfi->dbegin >= static_cast<int>(nLine))
return i;
break;
case THREEWAYDIFFTYPE_MIDDLERIGHT:
- if (dfi->op != OP_TRIVIAL && dfi->op != OP_1STONLY && dfi->dbegin[0] >= static_cast<int>(nLine))
+ if (dfi->op != OP_TRIVIAL && dfi->op != OP_1STONLY && dfi->dbegin >= static_cast<int>(nLine))
return i;
break;
case THREEWAYDIFFTYPE_LEFTONLY:
- if (dfi->op == OP_1STONLY && dfi->dbegin[0] >= static_cast<int>(nLine))
+ if (dfi->op == OP_1STONLY && dfi->dbegin >= static_cast<int>(nLine))
return i;
break;
case THREEWAYDIFFTYPE_MIDDLEONLY:
- if (dfi->op == OP_2NDONLY && dfi->dbegin[0] >= static_cast<int>(nLine))
+ if (dfi->op == OP_2NDONLY && dfi->dbegin >= static_cast<int>(nLine))
return i;
break;
case THREEWAYDIFFTYPE_RIGHTONLY:
- if (dfi->op == OP_3RDONLY && dfi->dbegin[0] >= static_cast<int>(nLine))
+ if (dfi->op == OP_3RDONLY && dfi->dbegin >= static_cast<int>(nLine))
return i;
break;
case THREEWAYDIFFTYPE_CONFLICT:
- if (dfi->op == OP_DIFF && dfi->dbegin[0] >= nLine)
+ if (dfi->op == OP_DIFF && dfi->dbegin >= nLine)
return i;
break;
}
}
}
-void DiffList::AppendDiffList(const DiffList& list, int offset[], int doffset[])
+void DiffList::AppendDiffList(const DiffList& list, int offset[], int doffset)
{
for (std::vector<DiffRangeInfo>::const_iterator it = list.m_diffs.begin(); it != list.m_diffs.end(); ++it)
{
dr.end[file] += offset[file];
}
if (doffset)
- {
- dr.dbegin[file] += doffset[file];
- dr.dend[file] += doffset[file];
- }
+ dr.blank[file] += doffset;
+ }
+ if (doffset)
+ {
+ dr.dbegin += doffset;
+ dr.dend += doffset;
}
AddDiff(dr);
}
{
int begin[3]; /**< First diff line in original file1,2,3 */
int end[3]; /**< Last diff line in original file1,2,3 */
- int dbegin[3]; /**< Synchronised (ghost lines added) first diff line in file1,2,3 */
- int dend[3]; /**< Synchronised (ghost lines added) last diff line in file1,2,3 */
+ int dbegin; /**< Synchronised (ghost lines added) first diff line in file1,2,3 */
+ int dend; /**< Synchronised (ghost lines added) last diff line in file1,2,3 */
int blank[3]; /**< Number of blank lines in file1,2,3 */
OP_TYPE op; /**< Operation done with this diff */
DIFFRANGE()
std::vector<DiffRangeInfo>& GetDiffRangeInfoVector() { return m_diffs; }
- void AppendDiffList(const DiffList& list, int offset[] = NULL, int doffset[] = NULL);
+ void AppendDiffList(const DiffList& list, int offset[] = NULL, int doffset = 0);
private:
std::vector<DiffRangeInfo> m_diffs; /**< Difference list. */
int bs[4] = {0};
int minY = INT_MAX, maxY = -1;
- bs[nBlocks++] = diff.dbegin[0];
+ bs[nBlocks++] = diff.dbegin;
for (i = 0; i < pDoc->m_nBuffers; i++)
{
if (diff.blank[i] >= 0)
bs[nBlocks++] = minY;
bs[nBlocks++] = maxY;
}
- bs[nBlocks] = diff.dend[0] + 1;
+ bs[nBlocks] = diff.dend + 1;
if (bs[nBlocks] >= nLineCount)
bs[nBlocks] = nLineCount - 1;
{
SetCurrentDiff(i);
const DIFFRANGE *pdi = m_diffList.DiffRangeAt(i);
- if (currentPosDst.y > pdi->dend[dstPane])
+ if (currentPosDst.y > pdi->dend)
{
if (pdi->blank[dstPane] >= 0)
- currentPosDst.y -= pdi->dend[dstPane] - pdi->blank[dstPane] + 1;
+ currentPosDst.y -= pdi->dend - pdi->blank[dstPane] + 1;
else if (pdi->blank[srcPane] >= 0)
- currentPosDst.y -= pdi->dend[dstPane] - pdi->blank[srcPane] + 1;
+ currentPosDst.y -= pdi->dend - pdi->blank[srcPane] + 1;
}
// Group merge with previous (merge undo data to one action)
bGroupWithPrevious = true;
if (srcPane != -1)
{
SetCurrentDiff(i);
- if (currentPosDst.y > pdi->dend[dstPane])
+ if (currentPosDst.y > pdi->dend)
{
if (pdi->blank[dstPane] >= 0)
- currentPosDst.y -= pdi->dend[dstPane] - pdi->blank[dstPane] + 1;
+ currentPosDst.y -= pdi->dend - pdi->blank[dstPane] + 1;
else if (pdi->blank[srcPane] >= 0)
- currentPosDst.y -= pdi->dend[dstPane] - pdi->blank[srcPane] + 1;
+ currentPosDst.y -= pdi->dend - pdi->blank[srcPane] + 1;
}
// Group merge with previous (merge undo data to one action)
if (!ListCopy(srcPane, dstPane, -1, bGroupWithPrevious, false))
*/
bool CMergeDoc::SanityCheckDiff(DIFFRANGE dr) const
{
- const int cd_dbegin = dr.dbegin[0];
- const int cd_dend = dr.dend[0];
+ const int cd_dbegin = dr.dbegin;
+ const int cd_dend = dr.dend;
int nBuffer;
// Must ensure line number is in range before getting line flags
CDiffTextBuffer& sbuf = *m_ptBuf[srcPane];
CDiffTextBuffer& dbuf = *m_ptBuf[dstPane];
bool bSrcWasMod = sbuf.IsModified();
- const int cd_dbegin = cd.dbegin[srcPane];
- const int cd_dend = cd.dend[srcPane];
+ const int cd_dbegin = cd.dbegin;
+ const int cd_dend = cd.dend;
const int cd_blank = cd.blank[srcPane];
bool bInSync = SanityCheckDiff(cd);
lcount[file] -= nline[file];
- // set dbegin, dend, blank, and line flags
- curDiff.dbegin[file] = lcountnew[file];
}
+ // set dbegin, dend, blank, and line flags
+ curDiff.dbegin = lcountnew[0];
switch (curDiff.op)
{
case OP_3RDONLY:
// set curdiff
{
+ curDiff.dend = lcountnew[0]+nmaxline-1;
for (file = 0; file < m_nBuffers; file++)
{
- curDiff.dend[file] = lcountnew[file]+nmaxline-1;
curDiff.blank[file] = -1;
int nextra = nmaxline - nline[file];
if (nmaxline > nline[file])
{
// more lines on left, ghost lines on right side
- curDiff.blank[file] = curDiff.dend[file]+1 - nextra;
+ curDiff.blank[file] = curDiff.dend + 1 - nextra;
}
}
}
{
// left side
int i;
- for (i = curDiff.dbegin[file]; i <= curDiff.dend[file] ; i++)
+ for (i = curDiff.dbegin; i <= curDiff.dend; i++)
{
if (curDiff.blank[file] == -1 || (int)i < curDiff.blank[file])
{
String str[3];
std::unique_ptr<int[]> nOffsets[3];
const int LineLimit = 20;
- bool diffPerLine = false;
-
- for (file = 0; file < m_nBuffers; file++)
+ bool diffPerLine = (cd.dend - cd.dbegin > LineLimit) ? true : false;
+
+ int nLineBegin, nLineEnd;
+ if (!diffPerLine)
{
- if (cd.dend[file] - cd.dbegin[file] > LineLimit)
- {
- diffPerLine = true;
- break;
- }
+ nLineBegin = cd.dbegin;
+ nLineEnd = cd.dend;
}
-
- int nLineBegins[3], nLineEnds[3];
- for (file = 0; file < m_nBuffers; file++)
+ else
{
- if (!diffPerLine)
- {
- nLineBegins[file] = cd.dbegin[file];
- nLineEnds[file] = cd.dend[file];
- }
- else
- {
- nLineBegins[file] = nLineEnds[file] = nLineIndex;
- }
+ nLineBegin = nLineEnd = nLineIndex;
}
for (file = 0; file < m_nBuffers; file++)
{
- int nLineBegin = nLineBegins[file], nLineEnd = nLineEnds[file];
nOffsets[file].reset(new int[nLineEnd - nLineBegin + 1]);
CString strText;
if (nLineBegin != nLineEnd || m_ptBuf[file]->GetLineLength(nLineEnd) > 0)
for (file = 0; file < m_nBuffers; file++)
{
int nLine;
- int nLineBegin = nLineBegins[file], nLineEnd = nLineEnds[file];
for (nLine = nLineBegin; nLine < nLineEnd; nLine++)
{
if (it->begin[file] == nOffsets[file][nLine-nLineBegin] || it->begin[file] < nOffsets[file][nLine-nLineBegin+1])
// Check that first selected line is first diff's first line or above it
VERIFY(pd->m_diffList.GetDiff(firstDiff, di));
- if ((int)di.dbegin[0] < firstLine)
+ if ((int)di.dbegin < firstLine)
{
if (firstDiff < lastDiff)
++firstDiff;
// Check that last selected line is last diff's last line or below it
VERIFY(pd->m_diffList.GetDiff(lastDiff, di));
- if ((int)di.dend[0] > lastLine)
+ if ((int)di.dend > lastLine)
{
if (firstDiff < lastDiff)
--lastDiff;
DIFFRANGE curDiff;
VERIFY(pd->m_diffList.GetDiff(nDiff, curDiff));
- newlineBegin = curDiff.dbegin[0];
+ newlineBegin = curDiff.dbegin;
ASSERT (newlineBegin >= 0);
- newlineEnd = curDiff.dend[0];
+ newlineEnd = curDiff.dend;
}
if (newlineBegin == m_lineBegin && newlineEnd == m_lineEnd)
{
// Enable if the beginning of the last significant difference is after caret
CPoint pos = GetCursorPos();
- pCmdUI->Enable(pos.y < (long)dfi->dbegin[0]);
+ pCmdUI->Enable(pos.y < (long)dfi->dbegin);
}
}
{
// Enable if the end of the first significant difference is before caret
CPoint pos = GetCursorPos();
- pCmdUI->Enable(pos.y > (long)dfi->dend[0]);
+ pCmdUI->Enable(pos.y > (long)dfi->dend);
}
}
{
// Enable if the beginning of the last significant difference is after caret
CPoint pos = GetCursorPos();
- pCmdUI->Enable(pos.y < (long)dfi->dbegin[0]);
+ pCmdUI->Enable(pos.y < (long)dfi->dbegin);
}
}
{
// Enable if the end of the first significant difference is before caret
CPoint pos = GetCursorPos();
- pCmdUI->Enable(pos.y > (long)dfi->dend[0]);
+ pCmdUI->Enable(pos.y > (long)dfi->dend);
}
}
pd->m_diffList.GetDiff(nDiff, curDiff);
ptStart.x = 0;
- ptStart.y = curDiff.dbegin[0];
+ ptStart.y = curDiff.dbegin;
ptEnd.x = 0;
- ptEnd.y = curDiff.dend[0];
+ ptEnd.y = curDiff.dend;
if (bScroll)
{
*/
bool CMergeEditView::IsDiffVisible(const DIFFRANGE& diff, int nLinesBelow /*=0*/)
{
- const int nDiffStart = GetSubLineIndex(diff.dbegin[0]);
- const int nDiffEnd = GetSubLineIndex(diff.dend[0]);
+ const int nDiffStart = GetSubLineIndex(diff.dbegin);
+ const int nDiffEnd = GetSubLineIndex(diff.dend);
// Diff's height is last line - first line + last line's line count
- const int nDiffHeight = nDiffEnd - nDiffStart + GetSubLines(diff.dend[0]) + 1;
+ const int nDiffHeight = nDiffEnd - nDiffStart + GetSubLines(diff.dend) + 1;
// If diff first line outside current view - context OR
// if diff last line outside current view - context OR