Skip to content

Commit

Permalink
Finding forwards in the output buffer will now match multiple items o…
Browse files Browse the repository at this point in the history
…n the same line
  • Loading branch information
nickgammon committed Nov 10, 2010
1 parent 5eb2c26 commit a023355
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
24 changes: 17 additions & 7 deletions Finding.cpp
Expand Up @@ -66,12 +66,12 @@ bool FindRoutine (const CObject * pObject, // passed back to callback rout
{
CFindDlg dlg (FindInfo.m_strFindStringList);

FindInfo.m_iStartColumn = -1; // return consistent column number

// find what the heck the user wants to do

if (!FindInfo.m_bAgain || FindInfo.m_strFindStringList.IsEmpty ())
{
FindInfo.m_iStartColumn = -1; // return consistent column number

if (!FindInfo.m_strFindStringList.IsEmpty ())
dlg.m_strFindText = FindInfo.m_strFindStringList.GetHead ();
Expand Down Expand Up @@ -117,12 +117,20 @@ CFindDlg dlg (FindInfo.m_strFindStringList);
} // end of not repeating the last find
else
{
if (FindInfo.m_bRepeatOnSameLine)
FindInfo.m_iStartColumn++; // skip previous match
else
FindInfo.m_iStartColumn = -1; // return consistent column number

// doing a "find again" - step past the line we were on

if (FindInfo.m_bForwards)
FindInfo.m_nCurrentLine++;
else
FindInfo.m_nCurrentLine--;
if (!FindInfo.m_bRepeatOnSameLine)
{
if (FindInfo.m_bForwards)
FindInfo.m_nCurrentLine++;
else
FindInfo.m_nCurrentLine--;
} // end of not repeating on same line

// re-initiate the search - this will set up the POSITION parameter, if it wants to

Expand Down Expand Up @@ -214,7 +222,7 @@ CString strStatus = TFormat ("Finding: %s", (LPCTSTR) FindInfo.m_strFindStringLi
if (FindInfo.m_bRegexp )
{

if (regexec (FindInfo.m_regexp, strLine))
if (regexec (FindInfo.m_regexp, strLine, maximum (FindInfo.m_iStartColumn, 0)))
{
// work out what column it must have been at
FindInfo.m_iStartColumn = FindInfo.m_regexp->m_vOffsets [0];
Expand All @@ -228,7 +236,7 @@ CString strStatus = TFormat ("Finding: %s", (LPCTSTR) FindInfo.m_strFindStringLi
// if case-insensitive search wanted, force this line to lower case
if (!FindInfo.m_bMatchCase)
strLine.MakeLower ();
if ((FindInfo.m_iStartColumn = strLine.Find (strFindString)) != -1)
if ((FindInfo.m_iStartColumn = strLine.Find (strFindString, maximum (FindInfo.m_iStartColumn, 0))) != -1)
{
// work out ending column
FindInfo.m_iEndColumn = FindInfo.m_iStartColumn +
Expand All @@ -240,6 +248,8 @@ CString strStatus = TFormat ("Finding: %s", (LPCTSTR) FindInfo.m_strFindStringLi

// keep track of line count

FindInfo.m_iStartColumn = -1; // back to start for next line

if (FindInfo.m_bForwards)
FindInfo.m_nCurrentLine++;
else
Expand Down
3 changes: 3 additions & 0 deletions sendvw.cpp
Expand Up @@ -1362,6 +1362,9 @@ ASSERT_VALID(pDoc);

pDoc->m_DisplayFindInfo.m_bAgain = bAgain;

// if finding forwards, we can find multiple instances on the same line
pDoc->m_DisplayFindInfo.m_bRepeatOnSameLine = pDoc->m_DisplayFindInfo.m_bForwards;

bool found = FindRoutine (pDoc, // passed back to callback routines
pDoc->m_DisplayFindInfo, // finding structure
InitiateSearch, // how to re-initiate a find
Expand Down
2 changes: 2 additions & 0 deletions stdafx.h
Expand Up @@ -259,6 +259,7 @@ class CFindInfo : public CObject
m_nCurrentLine = 0;
m_iControlColumns = 0;
m_regexp = NULL;
m_bRepeatOnSameLine = false;
}; // constructor

~CFindInfo () { delete m_regexp; };
Expand All @@ -279,6 +280,7 @@ class CFindInfo : public CObject
int m_iControlColumns; // number of columns in the control
t_regexp * m_regexp; // compiled regular expression
CStringList m_strFindStringList; // previous things we found
bool m_bRepeatOnSameLine; // keep trying to match on same line
};

// prototype for "get next line" callback for find routine
Expand Down

0 comments on commit a023355

Please sign in to comment.