@@ -69,13 +69,9 @@ export function indentItem(item: Item, indentLevel = 0): Item {
6969
7070 if ( item . isLeaf ( ) ) {
7171 return indentLeafValues ( item , indentedKey , indentLevel ) ;
72+ } else {
73+ return indentContainer ( item , indentedKey , indentLevel ) ;
7274 }
73-
74- indentLevel ++ ;
75- const children : Item [ ] = item . getChildren ( ) ! . map ( childLiteral => indentItem ( childLiteral , indentLevel ) ) ;
76-
77- return Item . createContainer ( item . getParent ( ) , indentedKey , children , item . getCondition ( ) ) ;
78-
7975}
8076
8177function indentLeafValues ( item : Item , indentedKey : Literal , indentLevel : number ) : Item {
@@ -95,6 +91,21 @@ function indentLeafValues(item: Item, indentedKey: Literal, indentLevel: number)
9591 return Item . createLeaf ( item . getParent ( ) , indentedKey , values , item . getCondition ( ) ) ;
9692}
9793
94+ function indentContainer ( item : Item , indentedKey : Literal , indentLevel : number ) : Item {
95+ indentLevel ++ ;
96+ const children : Item [ ] = item . getChildren ( ) ! . map ( childLiteral => indentItem ( childLiteral , indentLevel ) ) ;
97+
98+ const keyEnd : number = indentedKey . getPosition ( ) . getRange ( ) . getEnd ( ) ;
99+ const c = Item . createContainer ( item . getParent ( ) , indentedKey , children , item . getCondition ( ) ) ;
100+ c . startPopulatingContainer ( new Literal ( new Position ( indentedKey . getPosition ( ) . getLine ( ) , new Range ( keyEnd + 1 , keyEnd + 2 ) ) , "{" ) ) ;
101+
102+ const closingBracePos = c . getClosingBrace ( ) ! . getPosition ( ) ;
103+ const indentStart = getIndentSpacer ( indentLevel ) ;
104+ c . endPopulatingContainer ( new Literal ( new Position ( closingBracePos . getLine ( ) , new Range ( indentStart , indentStart + 1 ) ) , "}" ) ) ;
105+
106+ return c ;
107+ }
108+
98109function indentKey ( key : Literal , indentLevel : number ) : Literal {
99110 const k = key . copy ( ) ;
100111 k . getPosition ( ) . getRange ( ) . moveTo ( getIndentSpacer ( indentLevel ) ) ;
0 commit comments