mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-13 14:09:16 +02:00
fixed synedit multi replace with overlapping results
git-svn-id: trunk@9341 -
This commit is contained in:
parent
3fc416a384
commit
58e1fe7109
@ -66,7 +66,7 @@ function GetBlockMinIndent(const Source: string;
|
||||
StartPos, EndPos: integer): integer;
|
||||
function GetIndentStr(Indent: integer): string;
|
||||
procedure IndentText(const Source: string; Indent, TabWidth: integer;
|
||||
var NewSource: string);
|
||||
out NewSource: string);
|
||||
|
||||
// identifiers
|
||||
procedure GetIdentStartEndAtPosition(const Source:string; Position:integer;
|
||||
@ -251,7 +251,7 @@ function FindClassAncestorName(const Source, FormClassName: string): string;
|
||||
|
||||
// code search
|
||||
function SearchCodeInSource(const Source, Find: string; StartPos:integer;
|
||||
var EndFoundPosition: integer; CaseSensitive: boolean):integer;
|
||||
out EndFoundPosition: integer; CaseSensitive: boolean):integer;
|
||||
function ReadNextPascalAtom(const Source: string;
|
||||
var Position, AtomStart: integer): string;
|
||||
procedure ReadRawNextPascalAtom(const Source: string;
|
||||
@ -884,7 +884,7 @@ begin
|
||||
repeat
|
||||
// find a good position to insert the component
|
||||
// in front of next section and in front of procedures/functions
|
||||
Atom:=lowercase(ReadNextPascalAtom(Source.SOurce,Position,AtomStart));
|
||||
Atom:=lowercase(ReadNextPascalAtom(Source.Source,Position,AtomStart));
|
||||
if (Atom='procedure') or (Atom='function') or (Atom='end') or (Atom='class')
|
||||
or (Atom='constructor') or (Atom='destructor')
|
||||
or (Atom='public') or (Atom='private') or (Atom='protected')
|
||||
@ -961,7 +961,7 @@ begin
|
||||
end;
|
||||
|
||||
function SearchCodeInSource(const Source, Find: string; StartPos: integer;
|
||||
var EndFoundPosition: integer; CaseSensitive: boolean):integer;
|
||||
out EndFoundPosition: integer; CaseSensitive: boolean):integer;
|
||||
// search pascal atoms of Find in Source
|
||||
// returns the start pos
|
||||
var
|
||||
@ -2591,7 +2591,7 @@ begin
|
||||
end;
|
||||
|
||||
procedure IndentText(const Source: string; Indent, TabWidth: integer;
|
||||
var NewSource: string);
|
||||
out NewSource: string);
|
||||
|
||||
function UnindentTxt(CopyChars: boolean): integer;
|
||||
var
|
||||
|
@ -116,7 +116,7 @@ type
|
||||
public
|
||||
function InsertCodeTemplate(CursorPos,EndPos: TCodeXYPosition;
|
||||
TopLine: integer; CodeTemplate: TCodeToolTemplate;
|
||||
var NewPos: TCodeXYPosition; var NewTopLine: integer;
|
||||
out NewPos: TCodeXYPosition; out NewTopLine: integer;
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
function ExtractProcedureHeader(CursorPos: TCodeXYPosition;
|
||||
Attributes: TProcHeadAttributes; var ProcHead: string): boolean;
|
||||
@ -128,7 +128,7 @@ implementation
|
||||
|
||||
function TCodeTemplatesTool.InsertCodeTemplate(CursorPos,
|
||||
EndPos: TCodeXYPosition; TopLine: integer; CodeTemplate: TCodeToolTemplate;
|
||||
var NewPos: TCodeXYPosition; var NewTopLine: integer;
|
||||
out NewPos: TCodeXYPosition; out NewTopLine: integer;
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
var
|
||||
NewText: TMemoryStream;
|
||||
|
@ -579,10 +579,10 @@ implementation
|
||||
|
||||
function CompareCodeToolMainSources(Data1, Data2: Pointer): integer;
|
||||
var
|
||||
Src1, Src2: PtrInt;
|
||||
Src1, Src2: Pointer;
|
||||
begin
|
||||
Src1:=PtrInt(TCustomCodeTool(Data1).Scanner.MainCode);
|
||||
Src2:=PtrInt(TCustomCodeTool(Data2).Scanner.MainCode);
|
||||
Src1:=TCustomCodeTool(Data1).Scanner.MainCode;
|
||||
Src2:=TCustomCodeTool(Data2).Scanner.MainCode;
|
||||
if Src1<Src2 then
|
||||
Result:=-1
|
||||
else if Src1>Src2 then
|
||||
@ -3230,7 +3230,7 @@ begin
|
||||
if not InitCurCodeTool(Code) then exit;
|
||||
try
|
||||
Result:=FCurCodeTool.ChangeCreateFormStatement(-1,OldClassName,OldVarName,
|
||||
NewClassName,NewVarName,true,
|
||||
NewClassName,NewVarName,OnlyIfExists,
|
||||
SourceChangeCache);
|
||||
except
|
||||
on e: Exception do Result:=HandleException(e);
|
||||
|
@ -186,7 +186,7 @@ type
|
||||
function FindFile(const Filename: string;
|
||||
CreateIfNotExists: boolean): TFileStateCacheItem;
|
||||
function Check(const Filename: string; AFlag: TFileStateCacheItemFlag;
|
||||
var AFile: TFileStateCacheItem; var FlagIsSet: boolean): boolean;
|
||||
out AFile: TFileStateCacheItem; var FlagIsSet: boolean): boolean;
|
||||
procedure WriteDebugReport;
|
||||
procedure AddChangeTimeStampHandler(const Handler: TNotifyEvent);
|
||||
procedure RemoveChangeTimeStampHandler(const Handler: TNotifyEvent);
|
||||
@ -1929,7 +1929,7 @@ end;
|
||||
|
||||
function DbgS(const p: pointer): string;
|
||||
begin
|
||||
Result:=HexStr(PtrInt(p),2*sizeof(PtrInt));
|
||||
Result:=HexStr(p-nil,2*sizeof(PtrInt));
|
||||
end;
|
||||
|
||||
function DbgS(const e: extended): string;
|
||||
@ -2331,7 +2331,7 @@ begin
|
||||
end;
|
||||
|
||||
function TFileStateCache.Check(const Filename: string;
|
||||
AFlag: TFileStateCacheItemFlag; var AFile: TFileStateCacheItem;
|
||||
AFlag: TFileStateCacheItemFlag; out AFile: TFileStateCacheItem;
|
||||
var FlagIsSet: boolean): boolean;
|
||||
begin
|
||||
AFile:=FindFile(Filename,true);
|
||||
|
@ -324,7 +324,7 @@ begin
|
||||
i:=KeyWordToHashIndex(Identifier);
|
||||
IdentifierEnd:=Identifier;
|
||||
while IsIdentChar[IdentifierEnd[0]] do inc(IdentifierEnd);
|
||||
KeyWordLen:=(PtrInt(IdentifierEnd)-PtrInt(Identifier));
|
||||
KeyWordLen:=integer(IdentifierEnd-Identifier);
|
||||
dec(IdentifierEnd);
|
||||
if i>=0 then begin
|
||||
i:=FBucketStart[i];
|
||||
|
@ -83,7 +83,7 @@ type
|
||||
const UpperUnitName: string;
|
||||
var NamePos, InPos: TAtomPosition): boolean;
|
||||
function FindUnitInAllUsesSections(const UpperUnitName: string;
|
||||
var NamePos, InPos: TAtomPosition): boolean;
|
||||
out NamePos, InPos: TAtomPosition): boolean;
|
||||
function RenameUsedUnit(const OldUpperUnitName, NewUnitName,
|
||||
NewUnitInFile: string;
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
@ -140,7 +140,7 @@ type
|
||||
// Application.Createform statements
|
||||
function FindCreateFormStatement(StartPos: integer;
|
||||
const UpperClassName, UpperVarName: string;
|
||||
var Position: TAtomPosition): integer; // 0=found, -1=not found, 1=found, but wrong classname
|
||||
out Position: TAtomPosition): integer; // 0=found, -1=not found, 1=found, but wrong classname
|
||||
function AddCreateFormStatement(const AClassName, AVarName: string;
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
function RemoveCreateFormStatement(const UpperVarName: string;
|
||||
@ -155,7 +155,7 @@ type
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
|
||||
// Application.Title:=<string const> statements
|
||||
function FindApplicationTitleStatement(var StartPos, StringConstStartPos,
|
||||
function FindApplicationTitleStatement(out StartPos, StringConstStartPos,
|
||||
EndPos: integer): boolean;
|
||||
function GetApplicationTitleStatement(StringConstStartPos, EndPos: integer;
|
||||
var Title: string): boolean;
|
||||
@ -396,10 +396,12 @@ begin
|
||||
end;
|
||||
|
||||
function TStandardCodeTool.FindUnitInAllUsesSections(
|
||||
const UpperUnitName: string; var NamePos, InPos: TAtomPosition): boolean;
|
||||
const UpperUnitName: string; out NamePos, InPos: TAtomPosition): boolean;
|
||||
var SectionNode, UsesNode: TCodeTreeNode;
|
||||
begin
|
||||
Result:=false;
|
||||
NamePos.StartPos:=-1;
|
||||
InPos.StartPos:=-1;
|
||||
if (UpperUnitName='') or (length(UpperUnitName)>255) then exit;
|
||||
BuildTree(false);
|
||||
SectionNode:=Tree.Root;
|
||||
@ -2045,12 +2047,13 @@ end;
|
||||
|
||||
function TStandardCodeTool.FindCreateFormStatement(StartPos: integer;
|
||||
const UpperClassName, UpperVarName: string;
|
||||
var Position: TAtomPosition): integer;
|
||||
out Position: TAtomPosition): integer;
|
||||
// 0=found, -1=not found, 1=found, but wrong classname
|
||||
var MainBeginNode: TCodeTreeNode;
|
||||
ClassNameFits: boolean;
|
||||
begin
|
||||
Result:=-1;
|
||||
Position.StartPos:=-1;
|
||||
if (UpperClassName='') or (UpperVarName='') or (length(UpperClassName)>255)
|
||||
or (length(UpperVarName)>255) then exit;
|
||||
if StartPos<1 then begin
|
||||
@ -2290,7 +2293,7 @@ begin
|
||||
Result:= Result and SourceChangeCache.Apply;
|
||||
end;
|
||||
|
||||
function TStandardCodeTool.FindApplicationTitleStatement(var StartPos,
|
||||
function TStandardCodeTool.FindApplicationTitleStatement(out StartPos,
|
||||
StringConstStartPos, EndPos: integer): boolean;
|
||||
var
|
||||
MainBeginNode: TCodeTreeNode;
|
||||
|
@ -9027,12 +9027,18 @@ begin
|
||||
while nInLine > 0 do begin
|
||||
nFound := fTSearch.Results[n];
|
||||
{$IFDEF SYN_LAZARUS}
|
||||
nSearchLen := fTSearch.ResultLengths[n];
|
||||
CurReplace := fTSearch.GetReplace(n);
|
||||
nReplaceLen := Length(CurReplace);
|
||||
{$ENDIF}
|
||||
repeat
|
||||
nSearchLen := fTSearch.ResultLengths[n];
|
||||
CurReplace := fTSearch.GetReplace(n);
|
||||
nReplaceLen := Length(CurReplace);
|
||||
if bBackward then Dec(n) else Inc(n);
|
||||
Dec(nInLine);
|
||||
until (nInLine<0) or (nSearchLen>0);
|
||||
if nInLine<0 then break;
|
||||
{$ELSE}
|
||||
if bBackward then Dec(n) else Inc(n);
|
||||
Dec(nInLine);
|
||||
{$ENDIF}
|
||||
// Is the search result entirely in the search range?
|
||||
if not InValidSearchRange(nFound, nFound + nSearchLen) then continue;
|
||||
Inc(Result);
|
||||
|
@ -204,8 +204,14 @@ begin
|
||||
i := Pred(fResults.Count);
|
||||
while i >= 0 do begin
|
||||
{$IFDEF SYN_LAZARUS}
|
||||
if GetResult(i)>=First then
|
||||
if GetResult(i)>=First then begin
|
||||
dec(TSynEditSearchResult(fResults[i]).Start,Delta);
|
||||
if GetResult(i)<First then begin
|
||||
// search result overlaps with deletion -> delete this result
|
||||
TSynEditSearchResult(fResults[i]).Free;
|
||||
fResults.Delete(i);
|
||||
end;
|
||||
end;
|
||||
{$ELSE}
|
||||
if GetResult(i) <= First then break;
|
||||
fResults[i] := pointer(integer(fResults[i]) - Delta);
|
||||
|
Loading…
Reference in New Issue
Block a user