From bce545c4f839a10fdd7badc56451bfe7d3adfce6 Mon Sep 17 00:00:00 2001 From: mattias Date: Tue, 20 Apr 2010 16:24:36 +0000 Subject: [PATCH] codetools: fixed FindLineEndOrCodeInFrontOfPosition stopping at empty lines git-svn-id: trunk@24744 - --- components/codetools/basiccodetools.pas | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/components/codetools/basiccodetools.pas b/components/codetools/basiccodetools.pas index 1db5bbab4f..d170548836 100644 --- a/components/codetools/basiccodetools.pas +++ b/components/codetools/basiccodetools.pas @@ -2479,6 +2479,7 @@ var CodePos: Integer; LineEndPos: LongInt; LineStartPos: LongInt; + IsEmpty: Boolean; begin SrcStart:=MinPosition; if SrcStart<1 then SrcStart:=1; @@ -2497,17 +2498,30 @@ begin begin // line end in code found if (Result>SrcStart) and (Source[Result-1] in [#10,#13]) - and (Source[Result]<>Source[Result-1]) then dec(Result); + and (Source[Result]<>Source[Result-1]) then + dec(Result); // test if it is a comment line (a line without code and at least one // comment) CodePos:=0; LineEndPos:=Result; // go to line start TestPos:=Result; - while (TestPos>SrcStart) and (not (Source[TestPos-1] in [#10,#13])) do + IsEmpty:=true; + while (TestPos>SrcStart) do begin + case Source[TestPos-1] of + #10,#13: break; + ' ',#9: ; + else IsEmpty:=false; + end; dec(TestPos); - LineStartPos:=TestPos; + end; + if IsEmpty then begin + // empty line + exit; + end; + // read line from start to end + LineStartPos:=TestPos; while TestPos0 then begin - // there is code in the line + // the line is not empty Result:=CodePos+1; exit; end;