diff --git a/components/codetools/basiccodetools.pas b/components/codetools/basiccodetools.pas index 018f1def8f..2fcae492ed 100644 --- a/components/codetools/basiccodetools.pas +++ b/components/codetools/basiccodetools.pas @@ -76,6 +76,8 @@ function ExtractCommentContent(const ASource: string; CommentStart: integer; TrimPasDoc: boolean = false): string; function FindMainUnitHint(const ASource: string; out Filename: string): boolean; function InEmptyLine(const ASource: string; StartPos: integer): boolean; +function SkipResourceDirective(const ASource: string; StartPos, EndPos: integer; + NestedComments: boolean): integer; // indent function GetLineIndent(const Source: string; Position: integer): integer; @@ -3716,6 +3718,53 @@ begin Result:=true; end; +function SkipResourceDirective(const ASource: string; + StartPos, EndPos: integer; NestedComments: boolean): integer; +var + MaxPos: integer; + + function IsResourceDirective(DirNamePos: integer): boolean; + begin + if UpChars[ASource[DirNamePos]]<>'R' then exit(false); + if (DirNamePos < MaxPos) + and (UpChars[ASource[DirNamePos+1]] in [' ',#9]) then exit(true); + result:=CompareIdentifiers(@ASource[DirNamePos],'RESOURCE')=0; + end; + +var + i: integer; +begin + MaxPos:=length(ASource); + if (EndPos>0) and (EndPos<=MaxPos) then + MaxPos:=EndPos-1; + Result:=StartPos; + i:=StartPos; + while (i<=MaxPos) do begin + case ASource[i] of + '{': + if (i+1nil then begin SetIndentAndInsertPos(NearestProcNode,NearestProcNode.Desc<>ctnBeginBlock); + InsertPos:=SkipResourceDirective(InsertPos); exit; end; end; @@ -8145,8 +8147,8 @@ var end; if NearestProcNode<>nil then begin Indent:=0; - InsertPos:=FindLineEndOrCodeAfterPosition(NearestProcNode.EndPos); SetIndentAndInsertPos(NearestProcNode,true); + InsertPos:=SkipResourceDirective(InsertPos); exit; end; diff --git a/components/codetools/customcodetool.pas b/components/codetools/customcodetool.pas index 8ca6a6825b..b2118d4fa4 100644 --- a/components/codetools/customcodetool.pas +++ b/components/codetools/customcodetool.pas @@ -192,6 +192,7 @@ type SkipEmptyLines: boolean = false; IncludeLineEnd: boolean = false): integer; function FindLineEndOrCodeInFrontOfPosition(StartPos: integer; StopAtDirectives: boolean = true; SkipEmptyLines: boolean = false): integer; + function SkipResourceDirective(StartPos: integer): integer; function UpdateNeeded(Range: TLinkScannerRange): boolean; function UpdateNeeded(OnlyInterfaceNeeded: boolean): boolean; deprecated; // use UpdateNeeded(lsrImplementationStart) or UpdateNeeded(lsrEnd) @@ -2909,6 +2910,18 @@ begin end; end; +function TCustomCodeTool.SkipResourceDirective(StartPos: integer): integer; +var + LinkIndex, LinkEnd: integer; +begin + Result:=StartPos; + LinkIndex:=Scanner.LinkIndexAtCleanPos(StartPos); + if LinkIndex>=0 then begin + LinkEnd:=Scanner.LinkCleanedEndPos(LinkIndex); + Result:=BasicCodeTools.SkipResourceDirective(Src,StartPos,LinkEnd,Scanner.NestedComments); + end; +end; + procedure TCustomCodeTool.ClearIgnoreErrorAfter; begin IgnoreErrorAfter:=CodePosition(0,nil);