SynEdit: Current word markup: reduce search overhead

git-svn-id: trunk@39859 -
This commit is contained in:
martin 2013-01-15 01:06:37 +00:00
parent eabecb3943
commit 0308e3759d

View File

@ -79,6 +79,7 @@ type
FSearchStringMaxLines: Integer; FSearchStringMaxLines: Integer;
FSearch: TSynEditSearch; FSearch: TSynEditSearch;
FNextPosIdx, FNextPosRow: Integer; FNextPosIdx, FNextPosRow: Integer;
FNeedValidate, FNeedValidatePaint: Boolean;
FStartPoint : TPoint; // First found position, before TopLine of visible area FStartPoint : TPoint; // First found position, before TopLine of visible area
FSearchedEnd: TPoint; FSearchedEnd: TPoint;
@ -112,6 +113,8 @@ type
public public
constructor Create(ASynEdit : TSynEditBase); constructor Create(ASynEdit : TSynEditBase);
destructor Destroy; override; destructor Destroy; override;
procedure IncPaintLock; override;
procedure DecPaintLock; override;
procedure PrepareMarkupForRow(aRow: Integer); override; procedure PrepareMarkupForRow(aRow: Integer); override;
function GetMarkupAttributeAtRowCol(const aRow: Integer; function GetMarkupAttributeAtRowCol(const aRow: Integer;
@ -409,6 +412,22 @@ begin
inherited Destroy; inherited Destroy;
end; end;
procedure TSynEditMarkupHighlightAll.IncPaintLock;
begin
if FPaintLock = 0 then begin
FNeedValidatePaint := False;
FNeedValidate := False;
end;
inherited IncPaintLock;
end;
procedure TSynEditMarkupHighlightAll.DecPaintLock;
begin
inherited DecPaintLock;
if FPaintLock = 0 then
ValidateMatches(not FNeedValidatePaint);
end;
procedure TSynEditMarkupHighlightAll.SetSearchOptions(const AValue : TSynSearchOptions); procedure TSynEditMarkupHighlightAll.SetSearchOptions(const AValue : TSynSearchOptions);
begin begin
if fSearchOptions = AValue then exit; if fSearchOptions = AValue then exit;
@ -481,7 +500,7 @@ function TSynEditMarkupHighlightAll.FindMatches(AStartPoint, AEndPoint: TPoint;
var var
ptFoundStart, ptFoundEnd: TPoint; ptFoundStart, ptFoundEnd: TPoint;
begin begin
debugln(['FindMatches IDX=', AIndex,' # ',dbgs(AStartPoint),' - ',dbgs(AEndPoint), 'AStopAfterLine=',AStopAfterLine, ' cnt=',FMatches.Count]); //debugln(['FindMatches IDX=', AIndex,' # ',dbgs(AStartPoint),' - ',dbgs(AEndPoint), 'AStopAfterLine=',AStopAfterLine, ' cnt=',FMatches.Count]);
fSearch.Backwards := ABackward; fSearch.Backwards := ABackward;
While (true) do begin While (true) do begin
if not fSearch.FindNextOne(Lines, AStartPoint, AEndPoint, ptFoundStart, ptFoundEnd) if not fSearch.FindNextOne(Lines, AStartPoint, AEndPoint, ptFoundStart, ptFoundEnd)
@ -497,7 +516,7 @@ begin
end; end;
end; end;
Result := AEndPoint; Result := AEndPoint;
debugln(['FindMatches IDX=', AIndex, ' ## ',dbgs(Result)]); //debugln(['FindMatches IDX=', AIndex, ' ## ',dbgs(Result)]);
end; end;
procedure TSynEditMarkupHighlightAll.SetHideSingleMatch(AValue: Boolean); procedure TSynEditMarkupHighlightAll.SetHideSingleMatch(AValue: Boolean);
@ -584,6 +603,14 @@ var
FirstInvalIdx, LastInvalIdx: Integer; FirstInvalIdx, LastInvalIdx: Integer;
p: TPoint; p: TPoint;
begin begin
if FPaintLock > 0 then begin
FNeedValidate := True;
if not SkipPaint then
FNeedValidatePaint := True;
exit;
end;
FNeedValidate := False;
if (fSearchString = '') or (not MarkupInfo.IsEnabled) then begin if (fSearchString = '') or (not MarkupInfo.IsEnabled) then begin
fMatches.Count := 0; fMatches.Count := 0;
exit; exit;
@ -624,7 +651,7 @@ begin
end; end;
if not IsPosValid(FSearchedEnd) then if not IsPosValid(FSearchedEnd) then
FSearchedEnd.y := -1; FSearchedEnd.y := -1;
DebugLnEnter(['>>> ValidateMatches ', FFirstInvalidLine, ' - ',FLastInvalidLine, ' Cnt=',FMatches.Count, ' Idx: ', FirstInvalIdx, ' - ',LastInvalIdx, ' ',SynEdit.Name, ' # ',fSearchString]); //DebugLnEnter(['>>> ValidateMatches ', FFirstInvalidLine, ' - ',FLastInvalidLine, ' Cnt=',FMatches.Count, ' Idx: ', FirstInvalIdx, ' - ',LastInvalIdx, ' ',SynEdit.Name, ' # ',fSearchString]);
FindInitialize; FindInitialize;
@ -656,7 +683,7 @@ begin
then FStartPoint := Point(1, TopLine) // no previous match found then FStartPoint := Point(1, TopLine) // no previous match found
else FStartPoint := FMatches.EndPoint[0]; else FStartPoint := FMatches.EndPoint[0];
end; end;
debugln(['ValidateMatches: startpoint ', dbgs(FStartPoint)]); //debugln(['ValidateMatches: startpoint ', dbgs(FStartPoint)]);
if FMatches.Count > Idx then begin if FMatches.Count > Idx then begin
// Fill at start // Fill at start
Idx2 := Idx; Idx2 := Idx;
@ -737,9 +764,7 @@ begin
end; end;
if FMatches.Count = 0 then //DebugLnExit(['<<< ValidateMatches Cnt=',FMatches.Count]) //;
DebugLnExit(['<<< ValidateMatches Cnt=',FMatches.Count]) //;
else DebugLnExit(['<<< ValidateMatches Cnt=',FMatches.Count, ' # ', dbgs(FMatches.StartPoint[0]), ' # ', dbgs(FMatches.EndPoint[FMatches.Count-1])]);
FFirstInvalidLine := 0; FFirstInvalidLine := 0;
FLastInvalidLine := 0; FLastInvalidLine := 0;
FNextPosRow := -1; FNextPosRow := -1;
@ -989,24 +1014,16 @@ procedure TSynEditMarkupHighlightAllCaret.CheckState;
var var
t: String; t: String;
begin begin
if (not FStateChanged) or (Caret = nil) then begin if (not FStateChanged) or (Caret = nil) then
if FValidateNeeded then
ValidateMatches;
FValidateNeeded := False;
exit; exit;
end;
FStateChanged := False; FStateChanged := False;
t := GetCurrentText; t := GetCurrentText;
if (SearchString = t) and (SearchOptions = GetCurrentOption) then begin if (SearchString = t) and (SearchOptions = GetCurrentOption) then begin
SearchString := t; // Update old bounds SearchString := t; // Update old bounds
if FValidateNeeded then
ValidateMatches;
FValidateNeeded := False;
exit; exit;
end; end;
FValidateNeeded := False;
if (SearchString <> '') and if (SearchString <> '') and
( ((CompareCarets(FLowBound, FOldLowBound) = 0) and ( ((CompareCarets(FLowBound, FOldLowBound) = 0) and
(CompareCarets(Caret.LineBytePos, FUpBound) >= 0) and (MatchCount > 1) ) (CompareCarets(Caret.LineBytePos, FUpBound) >= 0) and (MatchCount > 1) )
@ -1041,7 +1058,6 @@ begin
( (HideSingleMatch) and (MatchCount > 1) ) ( (HideSingleMatch) and (MatchCount > 1) )
then then
inherited; inherited;
//FValidateNeeded := True;
end; end;
procedure TSynEditMarkupHighlightAllCaret.DoMarkupChanged(AMarkup: TSynSelectedColor); procedure TSynEditMarkupHighlightAllCaret.DoMarkupChanged(AMarkup: TSynSelectedColor);