codetools: indenter: fixed using right block when on block end

git-svn-id: trunk@22922 -
This commit is contained in:
mattias 2009-12-02 13:38:23 +00:00
parent 4b683366c7
commit 7dee2172f1

View File

@ -82,6 +82,7 @@ interface
{ $DEFINE ShowCodeBeautifier} { $DEFINE ShowCodeBeautifier}
{ $DEFINE ShowCodeBeautifierParser} { $DEFINE ShowCodeBeautifierParser}
{ $DEFINE ShowCodeBeautifierLearn} { $DEFINE ShowCodeBeautifierLearn}
{ $DEFINE VerboseIndenter}
{$IFDEF ShowCodeBeautifierParser} {$IFDEF ShowCodeBeautifierParser}
{$DEFINE ShowCodeBeautifierLearn} {$DEFINE ShowCodeBeautifierLearn}
@ -1618,17 +1619,18 @@ begin
exit(Indent.IndentValid); exit(Indent.IndentValid);
end; end;
Block:=Stack.Stack[StackIndex];
if (StackIndex<Stack.Top) then begin if (StackIndex<Stack.Top) then begin
// block(s) closed by next token // block(s) closed by next token
// use indent of block start // use indent of block start
Block:=Stack.Stack[StackIndex+1];
{$IFDEF VerboseIndenter} {$IFDEF VerboseIndenter}
DebugLn(['TFullyAutomaticBeautifier.GetIndent next token close block: ',FABBlockTypeNames[Stack.TopType]]); DebugLn(['TFullyAutomaticBeautifier.GetIndent next token close block: ',FABBlockTypeNames[Stack.TopType],' Block=',dbgstr(copy(Source,Block.StartPos,20))]);
{$ENDIF} {$ENDIF}
Indent.Indent:=GetLineIndentWithTabs(Source,Block.StartPos,DefaultTabWidth); Indent.Indent:=GetLineIndentWithTabs(Source,Block.StartPos,DefaultTabWidth);
Indent.IndentValid:=true; Indent.IndentValid:=true;
exit(true); exit(true);
end; end;
Block:=Stack.Stack[StackIndex];
// search last non empty line start // search last non empty line start
PrevLineAtomEndPos:=CleanPos; PrevLineAtomEndPos:=CleanPos;
@ -1679,6 +1681,9 @@ begin
if CheckPolicies(Policies,Result) then exit; if CheckPolicies(Policies,Result) then exit;
end; end;
finally finally
{$IFDEF VerboseIndenter}
DebugLn(['TFullyAutomaticBeautifier.GetIndent Valid=',Indent.IndentValid,' Indent=',Indent.Indent]);
{$ENDIF}
Stack.Free; Stack.Free;
if Policies<>nil then if Policies<>nil then
FreeAndNil(Policies.Code); FreeAndNil(Policies.Code);