OSDN Git Service

Fix GitHub issue #159: file compare : right-click doesn't select the diff under the...
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Wed, 3 Jul 2019 11:56:33 +0000 (20:56 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Wed, 3 Jul 2019 11:56:33 +0000 (20:56 +0900)
Externals/crystaledit/editlib/ccrystaltextview2.cpp
Src/MergeEditView.cpp
Src/MergeEditView.h

index ae71f85..f2859bb 100644 (file)
@@ -1096,7 +1096,7 @@ OnRButtonDown (UINT nFlags, CPoint point)
   pt = ClientToText (pt);
 
   // If there is selection, dont' clear it
-  if (!IsSelection())
+  if (!IsSelection() || !IsInsideSelBlock(pt))
     {
       m_ptAnchor = m_ptCursorPos = pt;
       SetSelection (m_ptCursorPos, m_ptCursorPos);
index 9f4a27b..6d2aeef 100644 (file)
@@ -137,6 +137,7 @@ BEGIN_MESSAGE_MAP(CMergeEditView, CCrystalEditViewEx)
        ON_UPDATE_COMMAND_UI(ID_PREVDIFFRO, OnUpdatePrevdiffRO)
        ON_WM_LBUTTONDBLCLK()
        ON_WM_LBUTTONUP()
+       ON_WM_RBUTTONDOWN()
        ON_COMMAND(ID_ALL_LEFT, OnAllLeft)
        ON_UPDATE_COMMAND_UI(ID_ALL_LEFT, OnUpdateAllLeft)
        ON_COMMAND(ID_ALL_RIGHT, OnAllRight)
@@ -942,6 +943,23 @@ void CMergeEditView::SelectDiff(int nDiff, bool bScroll /*= true*/, bool bSelect
        pd->ForEachView (0, [&](auto& pView) { if (pView->m_bDetailView) pView->OnDisplayDiff(nDiff); });
 }
 
+void CMergeEditView::DeselectDiffIfCursorNotInCurrentDiff()
+{
+       CMergeDoc *pd = GetDocument();
+       // If we have a selected diff, deselect it
+       int nCurrentDiff = pd->GetCurrentDiff();
+       if (nCurrentDiff != -1)
+       {
+               CPoint pos = GetCursorPos();
+               if (!IsLineInCurrentDiff(pos.y))
+               {
+                       pd->SetCurrentDiff(-1);
+                       Invalidate();
+                       pd->UpdateAllViews(this);
+               }
+       }
+}
+
 /**
  * @brief Called when user selects "Current Difference".
  * Goes to active diff. If no active diff, selects diff under cursor
@@ -1748,21 +1766,20 @@ void CMergeEditView::OnLButtonDblClk(UINT nFlags, CPoint point)
  */
 void CMergeEditView::OnLButtonUp(UINT nFlags, CPoint point)
 {
-       CMergeDoc *pd = GetDocument();
        CCrystalEditViewEx::OnLButtonUp(nFlags, point);
+       DeselectDiffIfCursorNotInCurrentDiff();
+}
 
-       // If we have a selected diff, deselect it
-       int nCurrentDiff = pd->GetCurrentDiff();
-       if (nCurrentDiff != -1)
-       {
-               CPoint pos = GetCursorPos();
-               if (!IsLineInCurrentDiff(pos.y))
-               {
-                       pd->SetCurrentDiff(-1);
-                       Invalidate();
-                       pd->UpdateAllViews(this);
-               }
-       }
+/**
+ * @brief Called when mouse right button is pressed.
+ *
+ * If right button is pressed outside diffs, current diff
+ * is deselected.
+ */
+void CMergeEditView::OnRButtonDown(UINT nFlags, CPoint point)
+{
+       CCrystalEditViewEx::OnRButtonDown(nFlags, point);
+       DeselectDiffIfCursorNotInCurrentDiff();
 }
 
 void CMergeEditView::OnX2Y(int srcPane, int dstPane)
index be511f1..1d152ca 100644 (file)
@@ -121,6 +121,7 @@ public:
        bool IsLineInCurrentDiff(int nLine) const;
        void SelectNone();
        void SelectDiff(int nDiff, bool bScroll = true, bool bSelectText = true);
+       void DeselectDiffIfCursorNotInCurrentDiff();
        virtual CCrystalTextBuffer *LocateTextBuffer ();
        const CCrystalTextBuffer *LocateTextBuffer () const { return const_cast<CMergeEditView *>(this)->LocateTextBuffer(); };
        void GetFullySelectedDiffs(int & firstDiff, int & lastDiff, int & firstWordDiff, int & lastWordDiff, const CPoint *pptStart = nullptr, const CPoint *ppEnd = nullptr);
@@ -255,6 +256,7 @@ protected:
        afx_msg void OnUpdatePrevdiffRO(CCmdUI* pCmdUI);
        afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
        afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
+       afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
        afx_msg void OnAllLeft();
        afx_msg void OnUpdateAllLeft(CCmdUI* pCmdUI);
        afx_msg void OnAllRight();