diff --git a/components/codetools/codebeautifier.pas b/components/codetools/codebeautifier.pas index 128b9b3feb..4f09c9ddd0 100644 --- a/components/codetools/codebeautifier.pas +++ b/components/codetools/codebeautifier.pas @@ -303,6 +303,7 @@ type Capacity: integer; Top: integer; TopType: TFABBlockType; + LastBlockClosed: TBlock; constructor Create; destructor Destroy; override; procedure BeginBlock(Typ: TFABBlockType; StartPos: integer); @@ -425,6 +426,8 @@ begin Block^.InnerIdent:=-1; Block^.InnerStartPos:=-1; TopType:=Typ; + LastBlockClosed.Typ:=bbtNone; + LastBlockClosed.StartPos:=0; end; procedure TFABBlockStack.EndBlock; @@ -432,10 +435,13 @@ begin {$IFDEF ShowCodeBeautifier} DebugLn([GetIndentStr(Top*2),'TFABBlockStack.EndBlock ',FABBlockTypeNames[TopType]]); {$ENDIF} + if Top<0 then + exit; dec(Top); - if Top>=0 then - TopType:=Stack[Top].Typ - else + if Top>=0 then begin + LastBlockClosed:=Stack[Top]; + TopType:=Stack[Top].Typ; + end else TopType:=bbtNone; end; @@ -1576,6 +1582,15 @@ begin exit(true); end; + if Stack.LastBlockClosed.StartPos>0 then begin + // a child block was closed + // => indent like the last child block one + Indent.Indent:=GetLineIndentWithTabs(Source, + Stack.LastBlockClosed.StartPos,DefaultTabWidth); + Indent.IndentValid:=true; + exit(true); + end; + {$IFDEF VerboseIndenter} DebugLn(['TFullyAutomaticBeautifier.GetIndent parsed code in front: context=',FABBlockTypeNames[Block.Typ],'/',FABBlockTypeNames[SubType],' indent=',GetLineIndentWithTabs(Source,Block.StartPos,DefaultTabWidth)]); {$ENDIF}