@@ -201,8 +201,10 @@ module ts {
201
201
firstCommentLineIndent = calculateIndent ( currentSourceFile . getPositionFromLineAndCharacter ( firstCommentLineAndCharacter . line , /*character*/ 1 ) ,
202
202
comment . pos ) ;
203
203
}
204
- var deltaIndent = calculateIndent ( pos , nextLineStart ) - firstCommentLineIndent ;
205
- if ( deltaIndent < 0 ) {
204
+
205
+ // Number of spacings this comment line differs from first comment line
206
+ var deltaIndentSpacing = calculateIndent ( pos , nextLineStart ) - firstCommentLineIndent ;
207
+ if ( deltaIndentSpacing < 0 ) {
206
208
// we need to decrease indent to get the desired effect
207
209
// Comment is left indented to first line
208
210
// eg
@@ -214,34 +216,36 @@ module ts {
214
216
// }
215
217
216
218
// Spaces to emit = indentSize - (numberof spaces in lastDeltaIndent) (in above eg (4 - 5%4) = 3)
217
- var spacesToEmit = ( deltaIndent % getIndentSize ( ) ) ; // This is negative of spaces to emit = -1 in above case
219
+ var spacesToEmit = ( deltaIndentSpacing % getIndentSize ( ) ) ; // This is negative of spaces to emit = -1 in above case
218
220
if ( spacesToEmit ) {
219
221
spacesToEmit += getIndentSize ( ) ; // Adjust the delta with the indentSize (4 - 1) = 3
220
222
}
221
223
222
- // Change in delta indent = deltaIndent / indentSize, we will change the delta to upper integer value
223
- // In above eg. 5/4 = 1.75 so change the indent two times
224
- var changeInIndent = ( - deltaIndent / getIndentSize ( ) ) ;
224
+ // This is number of times indent needs to be decremented before writing comment line text
225
+ // and same number of times the indent needs to be increased
226
+ // It = deltaIndentSpacing / indentSize, we will change this to upper integer value
227
+ // In above eg. 5/4 = 1.75 so change the indent two times (decrease 2 times, write text and then increase 2 times)
228
+ var indentChangeCount = ( - deltaIndentSpacing / getIndentSize ( ) ) ;
225
229
226
230
// If we cant go back as much as we want to, go to left most position
227
- if ( changeInIndent > writer . getIndent ( ) ) {
228
- changeInIndent = writer . getIndent ( ) ;
231
+ if ( indentChangeCount > writer . getIndent ( ) ) {
232
+ indentChangeCount = writer . getIndent ( ) ;
229
233
spacesToEmit = 0 ;
230
234
}
231
235
232
- // Decrease the chaneInIndent number of times
233
- for ( var i = 0 ; i < changeInIndent ; i ++ ) {
236
+ // Decrease the indentChangeCount number of times
237
+ for ( var i = 0 ; i < indentChangeCount ; i ++ ) {
234
238
writer . decreaseIndent ( ) ;
235
239
}
236
240
237
- // Emit either delta spaces or indentSizeSpaces
241
+ // Emit the spaces to maintain deltaIndentSpacing
238
242
emitSpaces ( spacesToEmit , writeNewLine ) ;
239
243
240
244
// Write the comment line text
241
245
writeNewLine = writeTrimmedCurrentLine ( pos , nextLineStart ) ;
242
246
243
247
// Revert the indent
244
- for ( var i = 0 ; i < changeInIndent ; i ++ ) {
248
+ for ( var i = 0 ; i < indentChangeCount ; i ++ ) {
245
249
writer . increaseIndent ( ) ;
246
250
}
247
251
} else {
@@ -255,7 +259,7 @@ module ts {
255
259
// }
256
260
// In above eg for line 2 in the comment, the delta is single space and hence emit that and emit the trimmed line
257
261
// but the third line has delta of 7 spaces and hence emit those spaces before emitting the trimmed line
258
- emitSpaces ( deltaIndent , writeNewLine ) ;
262
+ emitSpaces ( deltaIndentSpacing , writeNewLine ) ;
259
263
writeNewLine = writeTrimmedCurrentLine ( pos , nextLineStart ) ;
260
264
}
261
265
}
0 commit comments