OSDN Git Service

PATCH: [ 1531293 ] Fix wrong cursor position after find
authorKimmo Varis <kimmov@gmail.com>
Mon, 31 Jul 2006 15:37:06 +0000 (15:37 +0000)
committerKimmo Varis <kimmov@gmail.com>
Mon, 31 Jul 2006 15:37:06 +0000 (15:37 +0000)
Src/Changes.txt
Src/editlib/ccrystaltextview.cpp
Src/editlib/ccrystaltextview.h
Src/editlib/cfindtextdlg.cpp

index 30349ec..142d41e 100644 (file)
@@ -2,6 +2,10 @@ Src\Changes.txt
 Add new items to top.
 (This summarizes all changes to all files under Src, including Src\Languages.)
 
+2006-07-31 Kimmo
+ PATCH: [ 1531293 ] Fix wrong cursor position after find
+  Src: ccrystaltextview.cpp ccrystaltextview.h cfindtextdlg.cpp
+
 2006-07-30 Takashi
  BUG: [ 1528322 ] Crash when using F6 / Bugg for file differences
   Src: MergeEditView.cpp
index 214dce2..d817a48 100644 (file)
@@ -4345,8 +4345,16 @@ FindStringHelper (LPCTSTR pszFindWhere, LPCTSTR pszFindWhat, DWORD dwFlags, int
   return -1;
 }
 
+/** 
+ * @brief Select text in editor.
+ * @param [in] ptStartPos Star position for highlight.
+ * @param [in] nLength Count of characters to highlight.
+ * @param [in] bCursorToLeft If TRUE cursor is positioned to Left-end of text
+ *  selection, if FALSE cursor is positioned to right-end.
+ */
 BOOL CCrystalTextView::
-HighlightText (const CPoint & ptStartPos, int nLength, BOOL bReverse /*= FALSE*/)
+HighlightText (const CPoint & ptStartPos, int nLength,
+    BOOL bCursorToLeft /*= FALSE*/)
 {
   ASSERT_VALIDTEXTPOS (ptStartPos);
   CPoint ptEndPos = ptStartPos;
@@ -4366,7 +4374,7 @@ HighlightText (const CPoint & ptStartPos, int nLength, BOOL bReverse /*= FALSE*/
     }
   ASSERT_VALIDTEXTPOS (m_ptCursorPos);  //  Probably 'nLength' is bigger than expected...
 
-  m_ptCursorPos = bReverse ? ptStartPos : ptEndPos;
+  m_ptCursorPos = bCursorToLeft ? ptStartPos : ptEndPos;
   m_ptAnchor = m_ptCursorPos;
   SetSelection (ptStartPos, ptEndPos);
   UpdateCaret ();
index 6285dca..193451d 100644 (file)
@@ -800,9 +800,10 @@ public :
     BOOL FindText (LPCTSTR pszText, const CPoint & ptStartPos, DWORD dwFlags, BOOL bWrapSearch, CPoint * pptFoundPos);
     BOOL FindTextInBlock (LPCTSTR pszText, const CPoint & ptStartPos, const CPoint & ptBlockBegin, const CPoint & ptBlockEnd,
                           DWORD dwFlags, BOOL bWrapSearch, CPoint * pptFoundPos);
-    BOOL HighlightText (const CPoint & ptStartPos, int nLength, BOOL bReverse = FALSE);
+    BOOL HighlightText (const CPoint & ptStartPos, int nLength,
+      BOOL bCursorToLeft = FALSE);
 
-       // IME (input method editor)
+    // IME (input method editor)
     void UpdateCompositionWindowPos();
     void UpdateCompositionWindowFont();
 
index 5f806dc..349ae7b 100644 (file)
@@ -38,16 +38,17 @@ static char THIS_FILE[] = __FILE__;
 /////////////////////////////////////////////////////////////////////////////
 // CFindTextDlg dialog
 
-CFindTextDlg::CFindTextDlg (CCrystalTextView * pBuddy):CDialog (CFindTextDlg::IDD, NULL)
+CFindTextDlg::CFindTextDlg (CCrystalTextView * pBuddy)
+: CDialog (CFindTextDlg::IDD, NULL)
+, m_pBuddy(pBuddy)
+, m_nDirection(1)
+, m_bMatchCase(FALSE)
+, m_bWholeWord(FALSE)
+, m_bRegExp(FALSE)
+, m_ptCurrentPos(CPoint (0, 0))
 {
-  m_pBuddy = pBuddy;
   //{{AFX_DATA_INIT(CFindTextDlg)
-  m_nDirection = 1;
-  m_bMatchCase = FALSE;
-  m_bWholeWord = FALSE;
-  m_bRegExp = FALSE;
   //}}AFX_DATA_INIT
-  m_ptCurrentPos = CPoint (0, 0);
 }
 
 void CFindTextDlg::
@@ -97,6 +98,7 @@ void CFindTextDlg::OnOK ()
       UpdateLastSearch ();
 
       ASSERT (m_pBuddy != NULL);
+      BOOL bCursorToLeft = FALSE;
       DWORD dwSearchFlags = 0;
       if (m_bMatchCase)
         dwSearchFlags |= FIND_MATCH_CASE;
@@ -105,12 +107,17 @@ void CFindTextDlg::OnOK ()
       if (m_bRegExp)
         dwSearchFlags |= FIND_REGEXP;
       if (m_nDirection == 0)
-        dwSearchFlags |= FIND_DIRECTION_UP;
+        {
+          dwSearchFlags |= FIND_DIRECTION_UP;
+          // When finding upwards put cursor to begin of selection
+          bCursorToLeft = TRUE;
+         }
 
       m_ctlFindText.SaveState(_T("Files\\FindInFile"));
 
       CPoint ptTextPos;
-      if (!m_pBuddy->FindText (m_sText, m_ptCurrentPos, dwSearchFlags, TRUE, &ptTextPos))
+      if (!m_pBuddy->FindText (m_sText, m_ptCurrentPos, dwSearchFlags, TRUE,
+          &ptTextPos))
         {
           CString prompt;
           prompt.Format (IDS_EDIT_TEXT_NOT_FOUND, m_sText);
@@ -119,12 +126,8 @@ void CFindTextDlg::OnOK ()
           return;
         }
 
-      // Goto begin of selection if scrolling happens to left
-      BOOL bReverse = FALSE;
-      if (ptTextPos.x < m_ptCurrentPos.x)
-        bReverse = TRUE;
-        
-      m_pBuddy->HighlightText (ptTextPos, m_pBuddy->m_nLastFindWhatLen, bReverse);
+      m_pBuddy->HighlightText (ptTextPos, m_pBuddy->m_nLastFindWhatLen,
+          bCursorToLeft);
 
       CDialog::OnOK ();
     }