From b21088720ad5c5d46be34dc544a4631f8f986b12 Mon Sep 17 00:00:00 2001 From: mattias Date: Thu, 29 Oct 2009 13:06:34 +0000 Subject: [PATCH] codetools: auto indent: check if cursor in comment git-svn-id: trunk@22338 - --- components/codetools/codebeautifier.pas | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/components/codetools/codebeautifier.pas b/components/codetools/codebeautifier.pas index 1983c0607e..23ee0259c6 100644 --- a/components/codetools/codebeautifier.pas +++ b/components/codetools/codebeautifier.pas @@ -552,18 +552,33 @@ var var r: PChar; Block: PBlock; + LastP: LongInt; + CommentStartPos: LongInt; + CommentEndPos: LongInt; begin LastAtomStart:=0; LastAtomEnd:=0; p:=StartPos; if EndPos>length(Src) then EndPos:=length(Src)+1; repeat + LastP:=p; ReadRawNextPascalAtom(Src,p,AtomStart,NestedComments); //DebugLn(['TFullyAutomaticBeautifier.ParseSource Atom=',copy(Src,AtomStart,p-AtomStart)]); if p>EndPos then begin if (AtomStartEndPos then begin + // EndPos is in comment => return bounds of comment + LastAtomStart:=CommentStartPos; + LastAtomEnd:=CommentEndPos; + end; + end; end; break; 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)),'"']); ParseSource(Source,1,CleanPos,NewNestedComments,Stack,Policies, LastAtomStart,LastAtomEnd); - if LastAtomStart>0 then CleanPos:=LastAtomStart; WriteDebugReport('After parsing code in front:',Stack); if (LastAtomStart>0) and (CleanPos>LastAtomStart) then begin // in comment or atom @@ -1112,6 +1126,7 @@ begin GetDefaultSrcIndent(Source,CleanPos,NewNestedComments,Indent); exit(Indent.IndentValid); end; + if LastAtomStart>0 then CleanPos:=LastAtomStart; StackIndex:=Stack.Top; if UseLineStart then