OSDN Git Service

Implement Bitbucket issue#144: triple click to select whole line
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Fri, 7 Jun 2019 14:15:47 +0000 (23:15 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Fri, 7 Jun 2019 14:15:47 +0000 (23:15 +0900)
Externals/crystaledit/editlib/ccrystaltextview.cpp
Externals/crystaledit/editlib/ccrystaltextview.h
Externals/crystaledit/editlib/ccrystaltextview2.cpp

index 74d904a..a63b047 100644 (file)
@@ -519,6 +519,7 @@ CCrystalTextView::CCrystalTextView ()
 : m_nScreenChars(-1)
 , m_pFindTextDlg(nullptr)
 , m_CurSourceDef(nullptr)
+, m_dwLastDblClickTime(0)
 {
   memset(((CView*)this)+1, 0, sizeof(*this) - sizeof(class CView)); // AFX_ZERO_INIT_OBJECT (CView)
   m_rxnode = nullptr;
@@ -4496,7 +4497,14 @@ PreTranslateMessage (MSG * pMsg)
             return true;
         }
     }
-
+  else if (pMsg->message == WM_LBUTTONDBLCLK)
+       m_dwLastDblClickTime = GetTickCount();
+  else if (pMsg->message == WM_LBUTTONDOWN && (GetTickCount() - GetDoubleClickTime()) < m_dwLastDblClickTime)
+    {
+      m_dwLastDblClickTime = 0;
+      OnLButtonTrippleClk(static_cast<UINT>(pMsg->wParam), { GET_X_LPARAM(pMsg->lParam), GET_Y_LPARAM(pMsg->lParam) });
+      return true;
+    }
   return CView::PreTranslateMessage (pMsg);
 }
 
index c17c61d..e9fe275 100644 (file)
@@ -174,6 +174,7 @@ protected:
     bool m_bDraggingText;
     bool m_bDragSelection, m_bWordSelection, m_bLineSelection, m_bColumnSelection;
     UINT_PTR m_nDragSelTimer;
+       DWORD m_dwLastDblClickTime;
 
     CPoint m_ptDrawSelStart, m_ptDrawSelEnd;
 
@@ -875,6 +876,7 @@ protected :
     afx_msg void OnTimer (UINT_PTR nIDEvent);
     afx_msg void OnKillFocus (CWnd * pNewWnd);
     afx_msg void OnLButtonDblClk (UINT nFlags, CPoint point);
+    afx_msg void OnLButtonTrippleClk (UINT nFlags, CPoint point);
     afx_msg void OnEditCopy ();
     afx_msg void OnUpdateEditCopy (CCmdUI * pCmdUI);
     afx_msg void OnEditSelectAll ();
index b13c5fc..ae71f85 100644 (file)
@@ -707,68 +707,59 @@ OnMouseMove (UINT nFlags, CPoint point)
 
   if (m_bDragSelection)
     {
-      bool bOnMargin = point.x < GetMarginWidth ();
-
       AdjustTextPoint (point);
       CPoint ptNewCursorPos = ClientToText (point);
 
       CPoint ptStart, ptEnd;
       if (m_bLineSelection)
         {
-          if (bOnMargin)
+          if (ptNewCursorPos.y < m_ptAnchor.y ||
+                ptNewCursorPos.y == m_ptAnchor.y && ptNewCursorPos.x < m_ptAnchor.x)
             {
-              if (ptNewCursorPos.y < m_ptAnchor.y ||
-                    ptNewCursorPos.y == m_ptAnchor.y && ptNewCursorPos.x < m_ptAnchor.x)
-                {
-                                       CPoint  pos;
-                                       ptEnd = m_ptAnchor;
-                                       CharPosToPoint( ptEnd.y, ptEnd.x, pos );
-                                       if( GetSubLineIndex( ptEnd.y ) + pos.y == GetSubLineCount() - 1 )
-                                               ptEnd = SubLineEndToCharPos( ptEnd.y, pos.y );
-                                       else
-                                       {
-                                               int     nLine, nSubLine;
-                                               GetLineBySubLine( GetSubLineIndex( ptEnd.y ) + pos.y + 1, nLine, nSubLine );
-                                               ptEnd.y = nLine;
-                                               ptEnd.x = SubLineHomeToCharPos( nLine, nSubLine );
-                                       }
-                                       CharPosToPoint( ptNewCursorPos.y, ptNewCursorPos.x, pos );
-                                       ptNewCursorPos.x = SubLineHomeToCharPos( ptNewCursorPos.y, pos.y );
-                  m_ptCursorPos = ptNewCursorPos;
-                }
-              else
-                {
-                  ptEnd = m_ptAnchor;
-
-                                       CPoint  pos;
-                                       CharPosToPoint( ptEnd.y, ptEnd.x, pos );
-                                       ptEnd.x = SubLineHomeToCharPos( ptEnd.y, pos.y );
-
-                                       m_ptCursorPos = ptNewCursorPos;
-                                       CharPosToPoint( ptNewCursorPos.y, ptNewCursorPos.x, pos );
-                                       if( GetSubLineIndex( ptNewCursorPos.y ) + pos.y == GetSubLineCount() - 1 )
-                                               ptNewCursorPos.x = SubLineEndToCharPos( ptNewCursorPos.y, pos.y );
-                                       else
-                                       {
-                                               int     nLine, nSubLine;
-                                               GetLineBySubLine( GetSubLineIndex( ptNewCursorPos.y ) + pos.y + 1, nLine, nSubLine );
-                                               ptNewCursorPos.y = nLine;
-                                               ptNewCursorPos.x = SubLineHomeToCharPos( nLine, nSubLine );
-                                       }
-
-                                       int nLine, nSubLine;
-                                       GetLineBySubLine( GetSubLineIndex( m_ptCursorPos.y ) + pos.y, nLine, nSubLine );
-                                       m_ptCursorPos.y = nLine;
-                                       m_ptCursorPos.x = SubLineHomeToCharPos( nLine, nSubLine );
-                }
-              UpdateCaret ();
-              SetSelection (ptNewCursorPos, ptEnd);
-              return;
+                       CPoint  pos;
+                       ptEnd = m_ptAnchor;
+                       CharPosToPoint( ptEnd.y, ptEnd.x, pos );
+                       if( GetSubLineIndex( ptEnd.y ) + pos.y == GetSubLineCount() - 1 )
+                               ptEnd = SubLineEndToCharPos( ptEnd.y, pos.y );
+                       else
+                       {
+                               int     nLine, nSubLine;
+                               GetLineBySubLine( GetSubLineIndex( ptEnd.y ) + pos.y + 1, nLine, nSubLine );
+                               ptEnd.y = nLine;
+                               ptEnd.x = SubLineHomeToCharPos( nLine, nSubLine );
+                       }
+                       CharPosToPoint( ptNewCursorPos.y, ptNewCursorPos.x, pos );
+                       ptNewCursorPos.x = SubLineHomeToCharPos( ptNewCursorPos.y, pos.y );
+              m_ptCursorPos = ptNewCursorPos;
             }
+          else
+            {
+              ptEnd = m_ptAnchor;
 
-          //  Moving to normal selection mode
-          ::SetCursor (::LoadCursor (nullptr, IDC_IBEAM));
-          m_bLineSelection = m_bWordSelection = false;
+                       CPoint  pos;
+                       CharPosToPoint( ptEnd.y, ptEnd.x, pos );
+                       ptEnd.x = SubLineHomeToCharPos( ptEnd.y, pos.y );
+
+                       m_ptCursorPos = ptNewCursorPos;
+                       CharPosToPoint( ptNewCursorPos.y, ptNewCursorPos.x, pos );
+                       if( GetSubLineIndex( ptNewCursorPos.y ) + pos.y == GetSubLineCount() - 1 )
+                               ptNewCursorPos.x = SubLineEndToCharPos( ptNewCursorPos.y, pos.y );
+                       else
+                       {
+                               int     nLine, nSubLine;
+                               GetLineBySubLine( GetSubLineIndex( ptNewCursorPos.y ) + pos.y + 1, nLine, nSubLine );
+                               ptNewCursorPos.y = nLine;
+                               ptNewCursorPos.x = SubLineHomeToCharPos( nLine, nSubLine );
+                       }
+
+                       int nLine, nSubLine;
+                       GetLineBySubLine( GetSubLineIndex( m_ptCursorPos.y ) + pos.y, nLine, nSubLine );
+                       m_ptCursorPos.y = nLine;
+                       m_ptCursorPos.x = SubLineHomeToCharPos( nLine, nSubLine );
+            }
+          UpdateCaret ();
+          SetSelection (ptNewCursorPos, ptEnd);
+          return;
         }
 
       if (m_bWordSelection)
@@ -1070,6 +1061,16 @@ OnLButtonDblClk (UINT nFlags, CPoint point)
 }
 
 void CCrystalTextView::
+OnLButtonTrippleClk (UINT nFlags, CPoint point)
+{
+  if (point.x < GetMarginWidth ())
+    return;
+  // simulate a click on margin to select whole line
+  point.x = 0;
+  OnLButtonDown (nFlags, point);
+}
+
+void CCrystalTextView::
 OnEditCopy ()
 {
   Copy ();