OSDN Git Service

Fix crash in Test
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 10 May 2020 13:51:46 +0000 (22:51 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 10 May 2020 13:51:46 +0000 (22:51 +0900)
Src/GhostTextView.cpp
Src/MergeEditView.cpp

index e6749a6..1b89ad6 100644 (file)
@@ -97,6 +97,8 @@ void CGhostTextView::popPosition(SCursorPushed Ssrc, CPoint & pt)
                pt.y = GetLineCount()-1;
                pt.x = GetLineLength(pt.y);
        }
+       if (pt.y < 0)
+               pt.y = 0;
 }
 
 void CGhostTextView::pushPosition(SCursorPushed & Sdest, CPoint pt)
index 0eb52f8..3158091 100644 (file)
@@ -938,32 +938,20 @@ void CMergeEditView::OnDisplayDiff(int nDiff /*=0*/)
                newlineEnd = curDiff.dend;
        }
 
-       if (newlineBegin == m_lineBegin && newlineEnd == m_lineEnd)
-               return;
        m_lineBegin = newlineBegin;
        m_lineEnd = newlineEnd;
 
-       // scroll to the first line of the diff
-       ScrollToLine(m_lineBegin);
+       int nLineCount = GetLineCount();
+       if (m_lineBegin > nLineCount)
+               m_lineBegin = nLineCount - 1;
+       if (m_lineEnd > nLineCount)
+               m_lineEnd = nLineCount - 1;
 
-       // tell the others views about this diff (no need to call UpdateSiblingScrollPos)
-       CSplitterWnd *pSplitterWnd = GetParentSplitter(this, false);
+       if (m_nTopLine == newlineBegin)
+               return;
 
-       // pSplitterWnd is `nullptr` if WinMerge started minimized.
-       if (pSplitterWnd != nullptr)
-       {
-               int nRows = pSplitterWnd->GetRowCount ();
-               int nCols = pSplitterWnd->GetColumnCount ();
-               for (int nRow = 0; nRow < nRows; nRow++)
-               {
-                       for (int nCol = 0; nCol < nCols; nCol++)
-                       {
-                               CMergeEditView *pSiblingView = static_cast<CMergeEditView*>(GetSiblingView (nRow, nCol));
-                               if (pSiblingView != nullptr)
-                                       pSiblingView->OnDisplayDiff(nDiff);
-                       }
-               }
-       }
+       // scroll to the first line of the diff
+       ScrollToLine(m_lineBegin);
 
        // update the width of the horizontal scrollbar
        RecalcHorzScrollBar();
@@ -996,7 +984,7 @@ void CMergeEditView::SelectDiff(int nDiff, bool bScroll /*= true*/, bool bSelect
        UpdateSiblingScrollPos(false);
 
        // notify either side, as it will notify the other one
-       pd->ForEachView (0, [&](auto& pView) { if (pView->m_bDetailView) pView->OnDisplayDiff(nDiff); });
+       pd->ForEachView ([&](auto& pView) { if (pView->m_bDetailView) pView->OnDisplayDiff(nDiff); });
 }
 
 void CMergeEditView::DeselectDiffIfCursorNotInCurrentDiff()
@@ -4109,6 +4097,12 @@ bool CMergeEditView::QueryEditable()
  */
 bool CMergeEditView::EnsureInDiff(CPoint& pt)
 {
+       int nLineCount = GetLineCount();
+       if (m_lineBegin >= nLineCount)
+               m_lineBegin = nLineCount - 1;
+       if (m_lineEnd >= nLineCount)
+               m_lineEnd = nLineCount - 1;
+
        int diffLength = m_lineEnd - m_lineBegin + 1;
        // first get the degenerate case out of the way
        // no diff ?
@@ -4172,6 +4166,12 @@ void CMergeEditView::ScrollToSubLine(int nNewTopLine, bool bNoSmoothScroll /*= F
 {
        if (m_bDetailView)
        {
+               int nLineCount = GetLineCount();
+               if (m_lineBegin >= nLineCount)
+                       m_lineBegin = nLineCount - 1;
+               if (m_lineEnd >= nLineCount)
+                       m_lineEnd = nLineCount - 1;
+
                // ensure we remain in diff
                int sublineBegin = GetSubLineIndex(m_lineBegin);
                int sublineEnd = GetSubLineIndex(m_lineEnd) + GetSubLines(m_lineEnd) - 1;