OSDN Git Service

Fix Github issue #307(3): Diff Pane issues(2.)
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Thu, 7 May 2020 08:07:43 +0000 (17:07 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Thu, 7 May 2020 08:07:43 +0000 (17:07 +0900)
Externals/crystaledit/editlib/ccrystaltextview.h
Src/MergeEditView.cpp
Src/MergeEditView.h

index 818419d..78f31b3 100644 (file)
@@ -838,7 +838,7 @@ public :
 
     //  Operations
     virtual void EnsureVisible (CPoint pt);
-    void EnsureVisible (CPoint ptStart, CPoint ptEnd);
+    virtual void EnsureVisible (CPoint ptStart, CPoint ptEnd);
 
     //  Text search helpers
     CPoint GetSearchPos (DWORD dwSearchFlags);
index bd22f7e..0eb52f8 100644 (file)
@@ -2267,7 +2267,7 @@ void CMergeEditView::ShowDiff(bool bScroll, bool bSelectText)
                ptEnd.x = 0;
                ptEnd.y = curDiff.dend;
 
-               if (bScroll)
+               if (bScroll && !m_bDetailView)
                {
                        if (!IsDiffVisible(curDiff, CONTEXT_LINES_BELOW))
                        {
@@ -2631,7 +2631,9 @@ void CMergeEditView::OnUpdateCaret()
        else
                m_bCurrentLineIsDiff = false;
 
-       UpdateLocationViewPosition(m_nTopSubLine, m_nTopSubLine + GetScreenLines());
+       CWnd* pWnd = GetFocus();
+       if (!m_bDetailView || (pWnd && pWnd->m_hWnd == this->m_hWnd))
+               UpdateLocationViewPosition(m_nTopSubLine, m_nTopSubLine + GetScreenLines());
 }
 /**
  * @brief Select linedifference in the current line.
@@ -4101,6 +4103,103 @@ bool CMergeEditView::QueryEditable()
 }
 
 /**
+ * @brief Adjust the point to remain in the displayed diff
+ *
+ * @return Tells if the point has been changed
+ */
+bool CMergeEditView::EnsureInDiff(CPoint& pt)
+{
+       int diffLength = m_lineEnd - m_lineBegin + 1;
+       // first get the degenerate case out of the way
+       // no diff ?
+       if (diffLength == 0)
+       {
+               if (pt.y == m_lineBegin && pt.x == 0)
+                       return false;
+               pt.y = m_lineBegin;
+               pt.x = 0;
+               return true;
+       }
+
+       // not above diff
+       if (pt.y < m_lineBegin)
+       {
+               pt.y = m_lineBegin;
+               pt.x = 0;
+               return true;
+       }
+       // diff is defined and not below diff
+       if (m_lineEnd > -1 && pt.y > m_lineEnd)
+       {
+               pt.y = m_lineEnd;
+               pt.x = GetLineLength(pt.y);
+               return true;
+       }
+       return false;
+}
+
+void CMergeEditView::EnsureVisible(CPoint pt)
+{
+       CPoint ptNew = pt;
+       if (m_bDetailView)
+       {
+               // ensure we remain in diff
+               if (EnsureInDiff(ptNew))
+                       SetCursorPos(ptNew);
+       }
+       CCrystalTextView::EnsureVisible(ptNew);
+}
+
+void CMergeEditView::EnsureVisible(CPoint ptStart, CPoint ptEnd)
+{
+       CCrystalTextView::EnsureVisible(ptStart, ptEnd);
+}
+
+void CMergeEditView::SetSelection(const CPoint& ptStart, const CPoint& ptEnd, bool bUpdateView)
+{
+       CPoint ptStartNew = ptStart;
+       CPoint ptEndNew = ptEnd;
+       if (m_bDetailView)
+       {
+               // ensure we remain in diff
+               EnsureInDiff(ptStartNew);
+               EnsureInDiff(ptEndNew);
+       }
+       CCrystalTextView::SetSelection(ptStartNew, ptEndNew, bUpdateView);
+}
+
+void CMergeEditView::ScrollToSubLine(int nNewTopLine, bool bNoSmoothScroll /*= FALSE*/, bool bTrackScrollBar /*= TRUE*/)
+{
+       if (m_bDetailView)
+       {
+               // ensure we remain in diff
+               int sublineBegin = GetSubLineIndex(m_lineBegin);
+               int sublineEnd = GetSubLineIndex(m_lineEnd) + GetSubLines(m_lineEnd) - 1;
+               int diffLength = sublineEnd - sublineBegin + 1;
+               int displayLength = GetScreenLines();
+               if (diffLength <= displayLength)
+                       nNewTopLine = sublineBegin;
+               else
+               {
+                       if (nNewTopLine < sublineBegin)
+                               nNewTopLine = sublineBegin;
+                       if (nNewTopLine + displayLength - 1 > sublineEnd)
+                               nNewTopLine = GetSubLineIndex(sublineEnd - displayLength + 1);
+               }
+
+               CPoint pt = GetCursorPos();
+               if (EnsureInDiff(pt))
+                       SetCursorPos(pt);
+
+               CPoint ptSelStart, ptSelEnd;
+               GetSelection(ptSelStart, ptSelEnd);
+               if (EnsureInDiff(ptSelStart) || EnsureInDiff(ptSelEnd))
+                       SetSelection(ptSelStart, ptSelEnd);
+       }
+       CCrystalTextView::ScrollToSubLine(nNewTopLine, bNoSmoothScroll, bTrackScrollBar);
+}
+
+/**
  * @brief Called when user selects View/Zoom In from menu.
  */
 void CMergeEditView::OnViewZoomIn()
index 1502ea8..b6ca83e 100644 (file)
@@ -179,6 +179,11 @@ public:
        bool IsDiffVisible(int nDiff);
        void ZoomText(short amount);
        virtual bool QueryEditable() override;
+       virtual void EnsureVisible(CPoint pt) override;
+       virtual void EnsureVisible(CPoint ptStart, CPoint ptEnd) override;
+       bool EnsureInDiff(CPoint& pt);
+       void SetSelection(const CPoint& ptStart, const CPoint& ptEnd, bool bUpdateView = true) override;
+       void ScrollToSubLine(int nNewTopLine, bool bNoSmoothScroll = false, bool bTrackScrollBar = true) override;
 
        // Overrides
        // ClassWizard generated virtual function overrides