From e7b2caee7e9a513cbae01a0826de2250d4120383 Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Sat, 11 Nov 2023 18:43:32 +0900 Subject: [PATCH] Fix an issue where "Copy to Left/Right and Advance" would sometimes skip differences when comparing 3 files. refs #1234 --- Src/MergeEditView.cpp | 65 +++++++++++++++++++++++++++++++++++++------ Src/MergeEditView.h | 1 + 2 files changed, 58 insertions(+), 8 deletions(-) diff --git a/Src/MergeEditView.cpp b/Src/MergeEditView.cpp index 7cb374d9c06..f97d3ba2eda 100644 --- a/Src/MergeEditView.cpp +++ b/Src/MergeEditView.cpp @@ -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); } /** @@ -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); } /** diff --git a/Src/MergeEditView.h b/Src/MergeEditView.h index 94898dc1804..2ae45774f44 100644 --- a/Src/MergeEditView.h +++ b/Src/MergeEditView.h @@ -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();