MG: method jumping with compilr directives in front

git-svn-id: trunk@3236 -
This commit is contained in:
lazarus 2002-08-23 12:52:24 +00:00
parent fdf0b1a83c
commit 87302ee8a9
5 changed files with 24 additions and 14 deletions

View File

@ -143,7 +143,8 @@ function FindNextIdentifier(const Source: string; StartPos, MaxPos: integer
function FindFirstNonSpaceCharInLine(const Source: string;
Position: integer): integer;
function FindLineEndOrCodeInFrontOfPosition(const Source: string;
Position, MinPosition: integer; NestedComments: boolean): integer;
Position, MinPosition: integer; NestedComments: boolean;
StopAtDirectives: boolean): integer;
function FindLineEndOrCodeAfterPosition(const Source: string;
Position, MaxPosition: integer; NestedComments: boolean): integer;
function FindFirstLineEndInFrontOfInCode(const Source: string;
@ -1355,19 +1356,17 @@ begin
ReadComment(Result);
#10,#13:
exit;
#9,' ',';':
inc(Result);
else
begin
if (Source[Result]<=' ') or (Source[Result]=';') then
inc(Result)
else
exit;
end;
exit;
end;
end;
end;
function FindLineEndOrCodeInFrontOfPosition(const Source: string;
Position, MinPosition: integer; NestedComments: boolean): integer;
Position, MinPosition: integer; NestedComments: boolean;
StopAtDirectives: boolean): integer;
{ search backward for a line end or code
ignore line ends in comments or at the end of comment lines
(comment lines are lines without code and at least one comment)
@ -1414,7 +1413,8 @@ var SrcStart: integer;
else
dec(P);
end;
Result:=not ((P>=SrcStart) and (Source[P+1]='$'));
Result:=not (StopAtDirectives
and (P>=SrcStart) and (Source[P+1]='$'));
dec(P);
end;
')':
@ -1429,7 +1429,8 @@ var SrcStart: integer;
else
dec(P);
end;
Result:=not ((P>=SrcStart) and (Source[P+1]='$'));
Result:=not (StopAtDirectives
and (P>=SrcStart) and (Source[P+1]='$'));
dec(P,2);
end else
Result:=true;

View File

@ -116,6 +116,8 @@ type
var ALineStart, ALineEnd, AFirstAtomStart, ALastAtomEnd: integer);
function FindLineEndOrCodeAfterPosition(StartPos: integer): integer;
function FindLineEndOrCodeInFrontOfPosition(StartPos: integer): integer;
function FindLineEndOrCodeInFrontOfPosition(StartPos: integer;
StopAtDirectives: boolean): integer;
function FindFirstLineEndAfterInCode(StartPos: integer): integer;
function UpdateNeeded(OnlyInterfaceNeeded: boolean): boolean;
@ -1622,6 +1624,12 @@ end;
function TCustomCodeTool.FindLineEndOrCodeInFrontOfPosition(StartPos: integer
): integer;
begin
Result:=FindLineEndOrCodeInFrontOfPosition(StartPos,true);
end;
function TCustomCodeTool.FindLineEndOrCodeInFrontOfPosition(StartPos: integer;
StopAtDirectives: boolean): integer;
{ Searches a nice position in the cleaned source in front of StartPos.
It will skip any space or comments (not directives) till next
line end or compiler directive or code or include file end.
@ -1632,7 +1640,7 @@ begin
LinkIndex:=Scanner.LinkIndexAtCleanPos(StartPos);
LinkStart:=Scanner.Links[LinkIndex].CleanedPos;
Result:=BasicCodeTools.FindLineEndOrCodeInFrontOfPosition(Src,
StartPos,LinkStart,Scanner.NestedComments);
StartPos,LinkStart,Scanner.NestedComments,StopAtDirectives);
end;
function TCustomCodeTool.FindFirstLineEndAfterInCode(StartPos: integer

View File

@ -835,7 +835,8 @@ begin
// if there is a comment in front of the top position, it probably belongs
// to the destination code
// -> adjust the topline position, so that the comment is visible
NewTopLineCleanPos:=FindLineEndOrCodeInFrontOfPosition(NewTopLineCleanPos);
NewTopLineCleanPos:=FindLineEndOrCodeInFrontOfPosition(NewTopLineCleanPos,
false);
if (NewTopLineCleanPos>=1) and (Src[NewTopLineCleanPos] in [#13,#10])
then begin
inc(NewTopLineCleanPos);

View File

@ -129,7 +129,7 @@ begin
InsertAtom.EndPos:=ResourceCode.SourceLength+1;
end;
InsertAtom.StartPos:=BasicCodeTools.FindLineEndOrCodeInFrontOfPosition(Src,
InsertAtom.StartPos,1,false)+1;
InsertAtom.StartPos,1,false,true)+1;
InsertAtom.EndPos:=BasicCodeTools.FindLineEndOrCodeAfterPosition(Src,
InsertAtom.EndPos,SrcLen,false);
NewResData:=ResourceData;

View File

@ -848,7 +848,7 @@ function TStandardCodeTool.ChangeCreateFormStatement(StartPos: integer;
OnlyIfExists: boolean; SourceChangeCache: TSourceChangeCache): boolean;
var MainBeginNode: TCodeTreeNode;
OldPosition: TAtomPosition;
FromPos, ToPos, Indent: integer;
FromPos, ToPos: integer;
begin
Result:=false;
if (OldClassName='') or (length(OldClassName)>255)