Skip to content

Commit c6ec222

Browse files
committed
show all matches of the same line
now we have the 2nd indicator "move" (offset in the line) and highlight
1 parent d9fea6e commit c6ec222

File tree

1 file changed

+48
-60
lines changed

1 file changed

+48
-60
lines changed

src/SearchDlg.cpp

Lines changed: 48 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3917,54 +3917,47 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
39173917
boost::match_flag_type flags = boost::match_default | boost::format_all;
39183918
if (!bDotMatchesNewline)
39193919
flags |= boost::match_not_dot_newline;
3920-
long prevLineStart = 0;
3921-
long prevLineEnd = 0;
39223920
while (!bCancelled && regex_search(start, end, whatC, expression, flags))
39233921
{
39243922
if (whatC[0].matched)
39253923
{
39263924
nFound++;
39273925
if (m_bNotSearch)
39283926
break;
3929-
long posMatch = static_cast<long>(whatC[0].first - textFile.GetFileString().begin());
3930-
long lineStart = textFile.LineFromPosition(posMatch);
3931-
long lineEnd = textFile.LineFromPosition(static_cast<long>(whatC[0].second - textFile.GetFileString().begin()));
3932-
if ((lineStart != prevLineStart) || (lineEnd != prevLineEnd))
3927+
long posMatch = static_cast<long>(whatC[0].first - textFile.GetFileString().begin());
3928+
long lineStart = textFile.LineFromPosition(posMatch);
3929+
long lineEnd = textFile.LineFromPosition(static_cast<long>(whatC[0].second - textFile.GetFileString().begin()));
3930+
long lenLineEncodingPre = 0;
3931+
long colMatch = columnFromPosition(textFile.GetFileString(), posMatch, &lenLineEncodingPre);
3932+
long lenMatch = static_cast<long>(whatC[0].length());
3933+
for (long l = lineStart; l <= lineEnd; ++l)
39333934
{
3934-
long lenLineEncodingPre = 0;
3935-
long colMatch = columnFromPosition(textFile.GetFileString(), posMatch, &lenLineEncodingPre);
3936-
long lenMatch = static_cast<long>(whatC[0].length());
3937-
for (long l = lineStart; l <= lineEnd; ++l)
3935+
auto sLine = textFile.GetLineString(l);
3936+
long lenLineMatch = static_cast<long>(sLine.length()) - colMatch;
3937+
if (lenMatch < lenLineMatch)
39383938
{
3939-
auto sLine = textFile.GetLineString(l);
3940-
long lenLineMatch = static_cast<long>(sLine.length()) - colMatch;
3941-
if (lenMatch < lenLineMatch)
3942-
{
3943-
lenLineMatch = lenMatch;
3944-
}
3945-
sInfo.matchLinesNumbers.push_back(l);
3946-
sInfo.matchMovesNumbers.push_back(colMatch);
3947-
if (m_bCaptureSearch)
3948-
{
3949-
auto out = whatC.format(m_replaceString, flags);
3950-
sInfo.matchLines.push_back(std::move(out));
3951-
sInfo.matchLengths.push_back(static_cast<long>(out.length()));
3952-
}
3953-
else
3954-
{
3955-
sInfo.matchLines.push_back(std::move(sLine));
3956-
sInfo.matchLengths.push_back(lenLineMatch);
3957-
}
3958-
if (lenMatch > lenLineMatch)
3959-
{
3960-
colMatch = 1;
3961-
lenMatch -= lenLineMatch + lenLineEncodingPre;
3962-
}
3939+
lenLineMatch = lenMatch;
3940+
}
3941+
sInfo.matchLinesNumbers.push_back(l);
3942+
sInfo.matchMovesNumbers.push_back(colMatch);
3943+
if (m_bCaptureSearch)
3944+
{
3945+
auto out = whatC.format(m_replaceString, flags);
3946+
sInfo.matchLines.push_back(std::move(out));
3947+
sInfo.matchLengths.push_back(static_cast<long>(out.length()));
3948+
}
3949+
else
3950+
{
3951+
sInfo.matchLines.push_back(std::move(sLine));
3952+
sInfo.matchLengths.push_back(lenLineMatch);
3953+
}
3954+
if (lenMatch > lenLineMatch)
3955+
{
3956+
colMatch = 1;
3957+
lenMatch -= lenLineMatch + lenLineEncodingPre;
39633958
}
39643959
}
39653960
++sInfo.matchCount;
3966-
prevLineStart = lineStart;
3967-
prevLineEnd = lineEnd;
39683961
}
39693962
// update search position:
39703963
if (start == whatC[0].second)
@@ -3992,12 +3985,12 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
39923985
nFound++;
39933986
if (m_bNotSearch)
39943987
break;
3995-
long posMatch = static_cast<long>(whatC[0].first - textFile.GetFileString().begin());
3996-
long lineStart = textFile.LineFromPosition(posMatch);
3997-
long lineEnd = textFile.LineFromPosition(static_cast<long>(whatC[0].second - textFile.GetFileString().begin()));
3988+
long posMatch = static_cast<long>(whatC[0].first - textFile.GetFileString().begin());
3989+
long lineStart = textFile.LineFromPosition(posMatch);
3990+
long lineEnd = textFile.LineFromPosition(static_cast<long>(whatC[0].second - textFile.GetFileString().begin()));
39983991
long lenLineEncodingPre = 0;
3999-
long colMatch = columnFromPosition(textFile.GetFileString(), posMatch, &lenLineEncodingPre);
4000-
long lenMatch = static_cast<long>(whatC[0].length());
3992+
long colMatch = columnFromPosition(textFile.GetFileString(), posMatch, &lenLineEncodingPre);
3993+
long lenMatch = static_cast<long>(whatC[0].length());
40013994
if (m_bCaptureSearch)
40023995
{
40033996
auto out = whatC.format(m_replaceString, flags);
@@ -4008,31 +4001,26 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
40084001
}
40094002
else
40104003
{
4011-
if ((lineStart != prevLineStart) || (lineEnd != prevLineEnd))
4004+
for (long l = lineStart; l <= lineEnd; ++l)
40124005
{
4013-
for (long l = lineStart; l <= lineEnd; ++l)
4006+
auto sLine = textFile.GetLineString(l);
4007+
long lenLineMatch = static_cast<long>(sLine.length()) - colMatch;
4008+
if (lenMatch < lenLineMatch)
40144009
{
4015-
auto sLine = textFile.GetLineString(l);
4016-
long lenLineMatch = static_cast<long>(sLine.length()) - colMatch;
4017-
if (lenMatch < lenLineMatch)
4018-
{
4019-
lenLineMatch = lenMatch;
4020-
}
4021-
sInfo.matchLines.push_back(sLine);
4022-
sInfo.matchLinesNumbers.push_back(l);
4023-
sInfo.matchMovesNumbers.push_back(colMatch);
4024-
sInfo.matchLengths.push_back(lenLineMatch);
4025-
if (lenMatch > lenLineMatch)
4026-
{
4027-
colMatch = 1;
4028-
lenMatch -= lenLineMatch + lenLineEncodingPre;
4029-
}
4010+
lenLineMatch = lenMatch;
4011+
}
4012+
sInfo.matchLines.push_back(sLine);
4013+
sInfo.matchLinesNumbers.push_back(l);
4014+
sInfo.matchMovesNumbers.push_back(colMatch);
4015+
sInfo.matchLengths.push_back(lenLineMatch);
4016+
if (lenMatch > lenLineMatch)
4017+
{
4018+
colMatch = 1;
4019+
lenMatch -= lenLineMatch + lenLineEncodingPre;
40304020
}
40314021
}
40324022
}
40334023
++sInfo.matchCount;
4034-
prevLineStart = lineStart;
4035-
prevLineEnd = lineEnd;
40364024
}
40374025
// update search position:
40384026
if (start == whatC[0].second)

0 commit comments

Comments
 (0)