SynEdit: user highlight, find longest match

git-svn-id: trunk@42716 -
This commit is contained in:
martin 2013-09-10 11:04:23 +00:00
parent f97ad56e37
commit c7057e9467

View File

@ -347,7 +347,7 @@ type
FTermDict: TSynSearchTermDict; FTermDict: TSynSearchTermDict;
//FNextTermWIthSameWord: Array of Integer; //FNextTermWIthSameWord: Array of Integer;
FFindInsertIndex: Integer; FFindInsertIndex, FFindStartedAtIndex: Integer;
FFindLineY: Integer; FFindLineY: Integer;
FFindLineText, FFindLineTextEnd, FFindLineTextLower, FFindLineTextLowerEnd: PChar; FFindLineText, FFindLineTextEnd, FFindLineTextLower, FFindLineTextLowerEnd: PChar;
FBackward, FBackwardReplace: Boolean; FBackward, FBackwardReplace: Boolean;
@ -1364,7 +1364,7 @@ end;
procedure TSynEditMarkupHighlightAllMulti.DoMatchFound(MatchEnd: PChar; MatchIdx: Integer; procedure TSynEditMarkupHighlightAllMulti.DoMatchFound(MatchEnd: PChar; MatchIdx: Integer;
var IsMatch: Boolean; var StopSeach: Boolean); var IsMatch: Boolean; var StopSeach: Boolean);
var var
Len: Integer; i, NextInsertIdx, Len: Integer;
o: TSynSearchTerm; o: TSynSearchTerm;
MatchBegin: PChar; MatchBegin: PChar;
begin begin
@ -1405,10 +1405,38 @@ begin
break; break;
end; end;
IsMatch := MatchIdx >= 0; IsMatch := False; // Continue for longer match //MatchIdx >= 0;
if not IsMatch then if MatchIdx < 0 then
exit; exit;
NextInsertIdx := FFindInsertIndex;
if FBackwardReplace then
inc(NextInsertIdx); // because FFindInsertIndex was not increased;
i := NextInsertIdx;
if (NextInsertIdx > FFindStartedAtIndex) then begin
//only searching one line at a time. So only checking x
Assert(FFindLineY = FMatches.EndPoint[NextInsertIdx-1].Y);
While (i > FFindStartedAtIndex) and
(MatchBegin-FFindLineText+1 < FMatches.EndPoint[i-1].X) // Starts within or before previous
do
dec(i);
if (i < NextInsertIdx) and (Len <= (FMatches.EndPoint[i].X - FMatches.StartPoint[i].X))
then
i := NextInsertIdx;
end;
if (i < NextInsertIdx) then begin
DebugLn(['Replacing match at idx=', i, ' Back:', FFindInsertIndex-i, ' y=', FFindLineY,
' x1=', FMatches.StartPoint[i].X, ' x2=', MatchBegin-FFindLineText+1, ' with longer. Len=', Len]);
FMatches.StartPoint[i] := Point(MatchBegin-FFindLineText+1, FFindLineY);
FMatches.EndPoint[i] := Point(MatchBegin-FFindLineText+1+Len, FFindLineY);
if i + 1 < FFindInsertIndex then
FMatches.Delete(i+1, FFindInsertIndex - (i + 1));
if not FBackward then
FFindInsertIndex := i + 1
else assert(i = FFindInsertIndex);
end
else begin
if FBackwardReplace then begin if FBackwardReplace then begin
// Replace, only keep last match // Replace, only keep last match
FMatches.StartPoint[FFindInsertIndex] := Point(MatchBegin-FFindLineText+1, FFindLineY); FMatches.StartPoint[FFindInsertIndex] := Point(MatchBegin-FFindLineText+1, FFindLineY);
@ -1424,6 +1452,7 @@ begin
else else
FBackwardReplace := True; FBackwardReplace := True;
end; end;
end;
procedure TSynEditMarkupHighlightAllMulti.SetTerms(AValue: TSynSearchTermDict); procedure TSynEditMarkupHighlightAllMulti.SetTerms(AValue: TSynSearchTermDict);
begin begin
@ -1466,6 +1495,7 @@ var
begin begin
//debugln(['FindMatches IDX=', AIndex, ' Cnt=', Matches.Count, ' LCnt=', AEndPoint.y-AStartPoint.y , ' # ', FTerms[0].SearchTerm, ' # ',dbgs(AStartPoint),' - ',dbgs(AEndPoint), ' AStopAfterLine=',AStopAfterLine, ' Back=', dbgs(ABackward), ' ']); //debugln(['FindMatches IDX=', AIndex, ' Cnt=', Matches.Count, ' LCnt=', AEndPoint.y-AStartPoint.y , ' # ', FTerms[0].SearchTerm, ' # ',dbgs(AStartPoint),' - ',dbgs(AEndPoint), ' AStopAfterLine=',AStopAfterLine, ' Back=', dbgs(ABackward), ' ']);
FFindInsertIndex := AIndex; FFindInsertIndex := AIndex;
FFindStartedAtIndex := FFindInsertIndex;
FBackward := ABackward; // Currently supports only finding a single match FBackward := ABackward; // Currently supports only finding a single match
if ABackward then begin if ABackward then begin
@ -1483,6 +1513,7 @@ begin
if LineLen > 0 then begin if LineLen > 0 then begin
FFindLineY := AEndPoint.Y; FFindLineY := AEndPoint.Y;
FFindStartedAtIndex := FFindInsertIndex;
FFindLineText := @LineText[1]; FFindLineText := @LineText[1];
FFindLineTextEnd := FFindLineText + LineLen; FFindLineTextEnd := FFindLineText + LineLen;
FFindLineTextLower := @LineTextLower[1]; FFindLineTextLower := @LineTextLower[1];
@ -1519,6 +1550,7 @@ begin
if LineLen > 0 then begin if LineLen > 0 then begin
FFindLineY := AStartPoint.Y; FFindLineY := AStartPoint.Y;
FFindStartedAtIndex := FFindInsertIndex;
FFindLineText := @LineText[1]; FFindLineText := @LineText[1];
FFindLineTextEnd := FFindLineText + LineLen; FFindLineTextEnd := FFindLineText + LineLen;
FFindLineTextLower := @LineTextLower[1]; FFindLineTextLower := @LineTextLower[1];