Skip to content

Commit a023355

Browse files
committed
Finding forwards in the output buffer will now match multiple items on the same line
1 parent 5eb2c26 commit a023355

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

Finding.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ bool FindRoutine (const CObject * pObject, // passed back to callback rout
6666
{
6767
CFindDlg dlg (FindInfo.m_strFindStringList);
6868

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

7170
// find what the heck the user wants to do
7271

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

7676
if (!FindInfo.m_strFindStringList.IsEmpty ())
7777
dlg.m_strFindText = FindInfo.m_strFindStringList.GetHead ();
@@ -117,12 +117,20 @@ CFindDlg dlg (FindInfo.m_strFindStringList);
117117
} // end of not repeating the last find
118118
else
119119
{
120+
if (FindInfo.m_bRepeatOnSameLine)
121+
FindInfo.m_iStartColumn++; // skip previous match
122+
else
123+
FindInfo.m_iStartColumn = -1; // return consistent column number
124+
120125
// doing a "find again" - step past the line we were on
121126

122-
if (FindInfo.m_bForwards)
123-
FindInfo.m_nCurrentLine++;
124-
else
125-
FindInfo.m_nCurrentLine--;
127+
if (!FindInfo.m_bRepeatOnSameLine)
128+
{
129+
if (FindInfo.m_bForwards)
130+
FindInfo.m_nCurrentLine++;
131+
else
132+
FindInfo.m_nCurrentLine--;
133+
} // end of not repeating on same line
126134

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

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

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

241249
// keep track of line count
242250

251+
FindInfo.m_iStartColumn = -1; // back to start for next line
252+
243253
if (FindInfo.m_bForwards)
244254
FindInfo.m_nCurrentLine++;
245255
else

sendvw.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,9 @@ ASSERT_VALID(pDoc);
13621362

13631363
pDoc->m_DisplayFindInfo.m_bAgain = bAgain;
13641364

1365+
// if finding forwards, we can find multiple instances on the same line
1366+
pDoc->m_DisplayFindInfo.m_bRepeatOnSameLine = pDoc->m_DisplayFindInfo.m_bForwards;
1367+
13651368
bool found = FindRoutine (pDoc, // passed back to callback routines
13661369
pDoc->m_DisplayFindInfo, // finding structure
13671370
InitiateSearch, // how to re-initiate a find

stdafx.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ class CFindInfo : public CObject
259259
m_nCurrentLine = 0;
260260
m_iControlColumns = 0;
261261
m_regexp = NULL;
262+
m_bRepeatOnSameLine = false;
262263
}; // constructor
263264

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

284286
// prototype for "get next line" callback for find routine

0 commit comments

Comments
 (0)