mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-08 09:20:49 +02:00
codetools: auto indent: check if cursor in comment
git-svn-id: trunk@22338 -
This commit is contained in:
parent
0e80d8ba47
commit
b21088720a
@ -552,18 +552,33 @@ var
|
|||||||
var
|
var
|
||||||
r: PChar;
|
r: PChar;
|
||||||
Block: PBlock;
|
Block: PBlock;
|
||||||
|
LastP: LongInt;
|
||||||
|
CommentStartPos: LongInt;
|
||||||
|
CommentEndPos: LongInt;
|
||||||
begin
|
begin
|
||||||
LastAtomStart:=0;
|
LastAtomStart:=0;
|
||||||
LastAtomEnd:=0;
|
LastAtomEnd:=0;
|
||||||
p:=StartPos;
|
p:=StartPos;
|
||||||
if EndPos>length(Src) then EndPos:=length(Src)+1;
|
if EndPos>length(Src) then EndPos:=length(Src)+1;
|
||||||
repeat
|
repeat
|
||||||
|
LastP:=p;
|
||||||
ReadRawNextPascalAtom(Src,p,AtomStart,NestedComments);
|
ReadRawNextPascalAtom(Src,p,AtomStart,NestedComments);
|
||||||
//DebugLn(['TFullyAutomaticBeautifier.ParseSource Atom=',copy(Src,AtomStart,p-AtomStart)]);
|
//DebugLn(['TFullyAutomaticBeautifier.ParseSource Atom=',copy(Src,AtomStart,p-AtomStart)]);
|
||||||
if p>EndPos then begin
|
if p>EndPos then begin
|
||||||
if (AtomStart<EndPos) then begin
|
if (AtomStart<EndPos) then begin
|
||||||
LastAtomStart:=AtomStart;
|
LastAtomStart:=AtomStart;
|
||||||
LastAtomEnd:=p;
|
LastAtomEnd:=p;
|
||||||
|
end else begin
|
||||||
|
// EndPos between two atom: in space or comment
|
||||||
|
CommentStartPos:=FindNextNonSpace(Src,LastP);
|
||||||
|
if CommentStartPos<EndPos then begin
|
||||||
|
CommentEndPos:=FindCommentEnd(Src,CommentStartPos,NestedComments);
|
||||||
|
if CommentEndPos>EndPos then begin
|
||||||
|
// EndPos is in comment => return bounds of comment
|
||||||
|
LastAtomStart:=CommentStartPos;
|
||||||
|
LastAtomEnd:=CommentEndPos;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
break;
|
break;
|
||||||
end else if AtomStart=EndPos then
|
end else if AtomStart=EndPos then
|
||||||
@ -1104,7 +1119,6 @@ begin
|
|||||||
DebugLn(['TFullyAutomaticBeautifier.GetIndent "',dbgstr(copy(Source,CleanPos-10,10)),'|',dbgstr(copy(Source,CleanPos,10)),'"']);
|
DebugLn(['TFullyAutomaticBeautifier.GetIndent "',dbgstr(copy(Source,CleanPos-10,10)),'|',dbgstr(copy(Source,CleanPos,10)),'"']);
|
||||||
ParseSource(Source,1,CleanPos,NewNestedComments,Stack,Policies,
|
ParseSource(Source,1,CleanPos,NewNestedComments,Stack,Policies,
|
||||||
LastAtomStart,LastAtomEnd);
|
LastAtomStart,LastAtomEnd);
|
||||||
if LastAtomStart>0 then CleanPos:=LastAtomStart;
|
|
||||||
WriteDebugReport('After parsing code in front:',Stack);
|
WriteDebugReport('After parsing code in front:',Stack);
|
||||||
if (LastAtomStart>0) and (CleanPos>LastAtomStart) then begin
|
if (LastAtomStart>0) and (CleanPos>LastAtomStart) then begin
|
||||||
// in comment or atom
|
// in comment or atom
|
||||||
@ -1112,6 +1126,7 @@ begin
|
|||||||
GetDefaultSrcIndent(Source,CleanPos,NewNestedComments,Indent);
|
GetDefaultSrcIndent(Source,CleanPos,NewNestedComments,Indent);
|
||||||
exit(Indent.IndentValid);
|
exit(Indent.IndentValid);
|
||||||
end;
|
end;
|
||||||
|
if LastAtomStart>0 then CleanPos:=LastAtomStart;
|
||||||
|
|
||||||
StackIndex:=Stack.Top;
|
StackIndex:=Stack.Top;
|
||||||
if UseLineStart then
|
if UseLineStart then
|
||||||
|
Loading…
Reference in New Issue
Block a user