From 6a14cf5ef4f51c9f6ff9da90830573893ca5e4d0 Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Wed, 3 Jul 2019 20:56:33 +0900 Subject: [PATCH] Fix GitHub issue #159: file compare : right-click doesn't select the diff under the mouse --- .../crystaledit/editlib/ccrystaltextview2.cpp | 2 +- Src/MergeEditView.cpp | 43 +++++++++++++++------- Src/MergeEditView.h | 2 + 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/Externals/crystaledit/editlib/ccrystaltextview2.cpp b/Externals/crystaledit/editlib/ccrystaltextview2.cpp index ae71f8550..f2859bb4e 100644 --- a/Externals/crystaledit/editlib/ccrystaltextview2.cpp +++ b/Externals/crystaledit/editlib/ccrystaltextview2.cpp @@ -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); diff --git a/Src/MergeEditView.cpp b/Src/MergeEditView.cpp index 9f4a27b36..6d2aeefee 100644 --- a/Src/MergeEditView.cpp +++ b/Src/MergeEditView.cpp @@ -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) diff --git a/Src/MergeEditView.h b/Src/MergeEditView.h index be511f184..1d152cacf 100644 --- a/Src/MergeEditView.h +++ b/Src/MergeEditView.h @@ -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(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(); -- 2.11.0