Fix issue with synedit search if more than one instance exists

git-svn-id: trunk@34772 -
This commit is contained in:
martin 2012-01-18 12:39:07 +00:00
parent d5188c4108
commit 1c2e894162

View File

@ -47,12 +47,15 @@ uses
, LCLProc, SynRegExpr, SynEditMiscProcs, SynEditTypes , LCLProc, SynRegExpr, SynEditMiscProcs, SynEditTypes
{$ENDIF}; {$ENDIF};
procedure MakeCompTable(Sensitive: boolean); procedure MakeCompTable;
{$IFNDEF SYN_LAZARUS} {$IFNDEF SYN_LAZARUS}
procedure MakeDelimiterTable; procedure MakeDelimiterTable;
{$ENDIF} {$ENDIF}
type type
TByteArray256 = array[#0..#255] of Byte;
PByteArray256 = ^TByteArray256;
{$IFDEF SYN_LAZARUS} {$IFDEF SYN_LAZARUS}
TSynEditSearchResult = class TSynEditSearchResult = class
public public
@ -89,6 +92,7 @@ type
fRegExprReplace: string; fRegExprReplace: string;
fReplacement: string; fReplacement: string;
FBackwards: boolean; FBackwards: boolean;
CompTable: PByteArray256;
function GetResultLen(Index: integer): integer; function GetResultLen(Index: integer): integer;
procedure SetRegExpr(const NewValue: boolean); procedure SetRegExpr(const NewValue: boolean);
{$ENDIF} {$ENDIF}
@ -152,29 +156,18 @@ uses
SysUtils; SysUtils;
var var
CompTableSensitive: boolean; CompTableSensitive: TByteArray256;
CompTable: array[#0..#255] of Byte; CompTableNoneSensitive: TByteArray256;
{$IFNDEF SYN_LAZARUS} {$IFNDEF SYN_LAZARUS}
DelimTable: array[#0..#255] of boolean; DelimTable: array[#0..#255] of boolean;
{$ENDIF} {$ENDIF}
procedure MakeCompTable(Sensitive: Boolean); procedure MakeCompTable;
var var
I: Char; I: Char;
begin begin
if CompTableSensitive <> Sensitive then for I := #0 to #255 do CompTableSensitive[I] := ord(I);
begin for I := #0 to #255 do CompTableNoneSensitive[I] := ord(uppercase(I)[1]);
CompTableSensitive := Sensitive;
{$IFDEF FPC}
if Sensitive then
for I := #0 to #255 do CompTable[I] := ord(I)
else
for I := #0 to #255 do CompTable[I] := ord(uppercase(I)[1]);
{$ELSE}
for I := #0 to #255 do CompTable[I] := ord(I);
if not Sensitive then CharLowerBuff(PChar(@CompTable[#0]), 256);
{$ENDIF}
end;
end; end;
{$IFNDEF SYN_LAZARUS} {$IFNDEF SYN_LAZARUS}
@ -263,6 +256,8 @@ end;
constructor TSynEditSearch.Create; constructor TSynEditSearch.Create;
begin begin
inherited Create; inherited Create;
fSensitive := False;
CompTable := @CompTableNoneSensitive;
fResults := TList.Create; fResults := TList.Create;
{$IFDEF SYN_LAZARUS} {$IFDEF SYN_LAZARUS}
RegExprEngine:=TRegExpr.Create; RegExprEngine:=TRegExpr.Create;
@ -325,10 +320,10 @@ begin
PatLenPlus := PatLen + 1; PatLenPlus := PatLen + 1;
Look_At := 1; Look_At := 1;
for I := 0 to 255 do Shift[I] := PatLenPlus; for I := 0 to 255 do Shift[I] := PatLenPlus;
for I := 1 to PatLen do Shift[CompTable[Pat[i]]] := PatLenPlus - I; for I := 1 to PatLen do Shift[CompTable^[Pat[i]]] := PatLenPlus - I;
while Look_at < PatLen do while Look_at < PatLen do
begin begin
if CompTable[Pat[PatLen]] = CompTable[Pat[PatLen - (Look_at)]] then exit; if CompTable^[Pat[PatLen]] = CompTable^[Pat[PatLen - (Look_at)]] then exit;
inc(Look_at); inc(Look_at);
end; end;
fShiftInitialized := TRUE; fShiftInitialized := TRUE;
@ -361,13 +356,13 @@ begin
FoundLen:=PatLen; FoundLen:=PatLen;
while Run < TheEnd do while Run < TheEnd do
begin begin
if CompTable[Pat[Patlen]] <> CompTable[Run^] then if CompTable^[Pat[Patlen]] <> CompTable^[Run^] then
inc(Run, Shift[CompTable[(Run + 1)^]]) inc(Run, Shift[CompTable^[(Run + 1)^]])
else else
begin begin
J := Run - PatLen + 1; J := Run - PatLen + 1;
I := 1; I := 1;
while CompTable[Pat[I]] = CompTable[J^] do while CompTable^[Pat[I]] = CompTable^[J^] do
begin begin
if I = PatLen then if I = PatLen then
begin begin
@ -382,11 +377,11 @@ begin
inc(J); inc(J);
end; end;
{begin} //mh 2000-08-29 {begin} //mh 2000-08-29
// inc(Run, Look_At + Shift[CompTable[(Run + Look_at)^]] - 1); // inc(Run, Look_At + Shift[CompTable^[(Run + Look_at)^]] - 1);
Inc(Run, Look_At); Inc(Run, Look_At);
if Run >= TheEnd then if Run >= TheEnd then
break; break;
Inc(Run, Shift[CompTable[Run^]] - 1); Inc(Run, Shift[CompTable^[Run^]] - 1);
{end} //mh 2000-08-29 {end} //mh 2000-08-29
end; end;
end; end;
@ -522,7 +517,7 @@ var
if fSensitive then begin if fSensitive then begin
if p1^<>p2^ then exit(false); if p1^<>p2^ then exit(false);
end else begin end else begin
if CompTable[p1^]<>CompTable[p2^] then exit(false); if CompTable^[p1^]<>CompTable^[p2^] then exit(false);
end; end;
inc(p1); inc(p1);
inc(p2); inc(p2);
@ -936,7 +931,7 @@ begin
while (x>=0) and (x<=MaxPos) do begin while (x>=0) and (x<=MaxPos) do begin
//DebugLn(['TSynEditSearch.FindNextOne x=',x]); //DebugLn(['TSynEditSearch.FindNextOne x=',x]);
if ASupportUnicodeCase then FCondition := (SearchLen=0) or (Line[x]=SearchFor^) if ASupportUnicodeCase then FCondition := (SearchLen=0) or (Line[x]=SearchFor^)
else FCondition := (SearchLen=0) or (CompTable[Line[x]]=CompTable[SearchFor^]); else FCondition := (SearchLen=0) or (CompTable^[Line[x]]=CompTable^[SearchFor^]);
if FCondition then if FCondition then
begin begin
//DebugLn(['TSynEditSearch.FindNextOne First character found x=',x,' Line[x]=',Line[x]]); //DebugLn(['TSynEditSearch.FindNextOne First character found x=',x,' Line[x]=',Line[x]]);
@ -951,7 +946,7 @@ begin
end end
else else
begin begin
while (i<SearchLen) and (CompTable[Line[x+i]]=CompTable[SearchFor[i]]) do while (i<SearchLen) and (CompTable^[Line[x+i]]=CompTable^[SearchFor[i]]) do
inc(i); inc(i);
end; end;
@ -1008,7 +1003,9 @@ procedure TSynEditSearch.SetSensitive(const Value: Boolean);
begin begin
if fSensitive <> Value then begin if fSensitive <> Value then begin
fSensitive := Value; fSensitive := Value;
MakeCompTable(Value); if fSensitive
then CompTable := @CompTableSensitive
else CompTable := @CompTableNoneSensitive;
fShiftInitialized := FALSE; fShiftInitialized := FALSE;
{$IFDEF SYN_LAZARUS} {$IFDEF SYN_LAZARUS}
RegExprEngine.ModifierI:=not fSensitive; RegExprEngine.ModifierI:=not fSensitive;
@ -1125,8 +1122,7 @@ end;
{$ENDIF} {$ENDIF}
initialization initialization
CompTableSensitive := True; // force the table initialization MakeCompTable;
MakeCompTable(False);
{$IFNDEF SYN_LAZARUS} {$IFNDEF SYN_LAZARUS}
MakeDelimiterTable; MakeDelimiterTable;
{$ENDIF} {$ENDIF}