From 58e1fe7109cfef79202a61a2d9861d7faa6cad21 Mon Sep 17 00:00:00 2001 From: mattias Date: Tue, 23 May 2006 17:41:59 +0000 Subject: [PATCH] fixed synedit multi replace with overlapping results git-svn-id: trunk@9341 - --- components/codetools/basiccodetools.pas | 10 +++++----- components/codetools/codetemplatestool.pas | 4 ++-- components/codetools/codetoolmanager.pas | 8 ++++---- components/codetools/fileprocs.pas | 6 +++--- components/codetools/keywordfunclists.pas | 2 +- components/codetools/stdcodetools.pas | 15 +++++++++------ components/synedit/synedit.pp | 14 ++++++++++---- components/synedit/syneditsearch.pp | 8 +++++++- 8 files changed, 41 insertions(+), 26 deletions(-) diff --git a/components/codetools/basiccodetools.pas b/components/codetools/basiccodetools.pas index b09466299c..2f6934b193 100644 --- a/components/codetools/basiccodetools.pas +++ b/components/codetools/basiccodetools.pas @@ -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 diff --git a/components/codetools/codetemplatestool.pas b/components/codetools/codetemplatestool.pas index d9d227ea6b..a41c38a215 100644 --- a/components/codetools/codetemplatestool.pas +++ b/components/codetools/codetemplatestool.pas @@ -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; diff --git a/components/codetools/codetoolmanager.pas b/components/codetools/codetoolmanager.pas index 5c86072094..af11703a88 100644 --- a/components/codetools/codetoolmanager.pas +++ b/components/codetools/codetoolmanager.pas @@ -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 Src1Src2 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); diff --git a/components/codetools/fileprocs.pas b/components/codetools/fileprocs.pas index 8aba091b75..36dd24c8fb 100644 --- a/components/codetools/fileprocs.pas +++ b/components/codetools/fileprocs.pas @@ -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); diff --git a/components/codetools/keywordfunclists.pas b/components/codetools/keywordfunclists.pas index aaf1fff9c8..9232715909 100644 --- a/components/codetools/keywordfunclists.pas +++ b/components/codetools/keywordfunclists.pas @@ -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]; diff --git a/components/codetools/stdcodetools.pas b/components/codetools/stdcodetools.pas index 8cd477208a..6d5acde9ae 100644 --- a/components/codetools/stdcodetools.pas +++ b/components/codetools/stdcodetools.pas @@ -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:= 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; diff --git a/components/synedit/synedit.pp b/components/synedit/synedit.pp index f60ccd73a0..f8c4217585 100644 --- a/components/synedit/synedit.pp +++ b/components/synedit/synedit.pp @@ -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); diff --git a/components/synedit/syneditsearch.pp b/components/synedit/syneditsearch.pp index fdcad261a5..998357659d 100644 --- a/components/synedit/syneditsearch.pp +++ b/components/synedit/syneditsearch.pp @@ -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) 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);