Skip to content

Commit

Permalink
Fix an issue where "Copy to Left/Right and Advance" would sometimes s…
Browse files Browse the repository at this point in the history
…kip differences when comparing 3 files. refs #1234
  • Loading branch information
sdottaka committed Nov 11, 2023
1 parent f312d98 commit e7b2cae
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 8 deletions.
65 changes: 57 additions & 8 deletions Src/MergeEditView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2952,12 +2952,63 @@ void CMergeEditView::OnUpdateConvertEolTo(CCmdUI* pCmdUI)
/**
* @brief Copy diff from left to right and advance to next diff
*/
void CMergeEditView::OnL2RNext()
void CMergeEditView::OnX2YNext(int srcPane, int dstPane)
{
OnL2r();
if (GetDocument()->m_nBuffers > 2 && IsCursorInDiff()) // for 3-way file compare
CMergeDoc *pDoc = GetDocument();
if (pDoc->m_nBuffers < 3)
{
OnX2Y(srcPane, dstPane);
OnNextdiff();
OnNextdiff();
}
else
{
int currentDiff = pDoc->GetCurrentDiff();
if (currentDiff == -1 && m_bCurrentLineIsDiff)
currentDiff = pDoc->m_diffList.LineToDiff(GetCursorPos().y);
if (currentDiff != -1)
{
int nNextDiff = -1;
DIFFRANGE di, diNext;
pDoc->m_diffList.GetDiff(currentDiff, di);
pDoc->m_diffList.GetNextDiff(di.dend + 1, nNextDiff);
if (nNextDiff != -1)
{
pDoc->m_diffList.GetDiff(nNextDiff, diNext);
int nRealLine;
int nPane = srcPane;
if (diNext.end[nPane] - diNext.begin[nPane] < 0)
{
for (nPane = 0; nPane < pDoc->m_nBuffers; ++nPane)
if (diNext.end[nPane] - diNext.begin[nPane] >= 0)
break;
}
nRealLine = diNext.begin[nPane];
if (nPane == dstPane)
nRealLine += (di.end[srcPane] - di.begin[srcPane]) - (di.end[dstPane] - di.begin[dstPane]);

OnX2Y(srcPane, dstPane);

nNextDiff = pDoc->m_diffList.LineToDiff(pDoc->m_ptBuf[nPane]->ComputeApparentLine(nRealLine));
if (nNextDiff != -1)
SelectDiff(nNextDiff, true, false);
else
OnNextdiff();
}
else
{
OnX2Y(srcPane, dstPane);
}
}
}
}

/**
* @brief Copy diff from left to right and advance to next diff
*/
void CMergeEditView::OnL2RNext()
{
auto [srcPane, dstPane] = CMergeFrameCommon::MenuIDtoXY(ID_L2R, m_nThisPane, GetDocument()->m_nBuffers);
OnX2YNext(srcPane, dstPane);
}

/**
Expand All @@ -2973,10 +3024,8 @@ void CMergeEditView::OnUpdateL2RNext(CCmdUI* pCmdUI)
*/
void CMergeEditView::OnR2LNext()
{
OnR2l();
if (GetDocument()->m_nBuffers > 2 && IsCursorInDiff()) // for 3-way file compare
OnNextdiff();
OnNextdiff();
auto [srcPane, dstPane] = CMergeFrameCommon::MenuIDtoXY(ID_R2L, m_nThisPane, GetDocument()->m_nBuffers);
OnX2YNext(srcPane, dstPane);
}

/**
Expand Down
1 change: 1 addition & 0 deletions Src/MergeEditView.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ class CMergeEditView : public CGhostTextView
afx_msg void OnConvertEolTo(UINT nID );
afx_msg void OnUpdateConvertEolTo(CCmdUI* pCmdUI);
afx_msg void OnUpdateStatusEOL(CCmdUI* pCmdUI);
afx_msg void OnX2YNext(int srcPane, int dstPane);
afx_msg void OnL2RNext();
afx_msg void OnUpdateL2RNext(CCmdUI* pCmdUI);
afx_msg void OnR2LNext();
Expand Down

0 comments on commit e7b2cae

Please sign in to comment.