@@ -21,21 +21,6 @@ module ts.server {
21
21
}
22
22
return spaceCache [ n ] ;
23
23
}
24
-
25
- export function generateIndentString ( n : number , editorOptions : EditorOptions ) : string {
26
- if ( editorOptions . ConvertTabsToSpaces ) {
27
- return generateSpaces ( n ) ;
28
- } else {
29
- var result = "" ;
30
- for ( var i = 0 ; i < Math . floor ( n / editorOptions . TabSize ) ; i ++ ) {
31
- result += "\t" ;
32
- }
33
- for ( var i = 0 ; i < n % editorOptions . TabSize ; i ++ ) {
34
- result += " " ;
35
- }
36
- return result ;
37
- }
38
- }
39
24
40
25
interface FileStart {
41
26
file : string ;
@@ -556,29 +541,31 @@ module ts.server {
556
541
var editorOptions : ts . EditorOptions = {
557
542
IndentSize : formatOptions . IndentSize ,
558
543
TabSize : formatOptions . TabSize ,
559
- NewLineCharacter : formatOptions . NewLineCharacter ,
544
+ NewLineCharacter : "\n" ,
560
545
ConvertTabsToSpaces : formatOptions . ConvertTabsToSpaces ,
561
546
} ;
562
- var preferredIndent = compilerService . languageService . getIndentationAtPosition ( file , position , editorOptions ) ;
563
- var hasIndent = 0 ;
547
+ var indentPosition =
548
+ compilerService . languageService . getIndentationAtPosition ( file , position , editorOptions ) ;
564
549
for ( var i = 0 , len = lineText . length ; i < len ; i ++ ) {
565
550
if ( lineText . charAt ( i ) == " " ) {
566
- hasIndent ++ ;
551
+ indentPosition -- ;
567
552
}
568
553
else if ( lineText . charAt ( i ) == "\t" ) {
569
- hasIndent + = editorOptions . TabSize ;
554
+ indentPosition - = editorOptions . IndentSize ;
570
555
}
571
556
else {
572
557
break ;
573
558
}
574
559
}
575
- // i points to the first non whitespace character
576
- if ( preferredIndent !== hasIndent ) {
577
- var firstNoWhiteSpacePosition = lineInfo . offset + i ;
578
- edits . push ( {
579
- span : ts . createTextSpanFromBounds ( lineInfo . offset , firstNoWhiteSpacePosition ) ,
580
- newText : generateIndentString ( preferredIndent , editorOptions )
581
- } ) ;
560
+ if ( indentPosition > 0 ) {
561
+ var spaces = generateSpaces ( indentPosition ) ;
562
+ edits . push ( { span : ts . createTextSpanFromBounds ( position , position ) , newText : spaces } ) ;
563
+ }
564
+ else if ( indentPosition < 0 ) {
565
+ edits . push ( {
566
+ span : ts . createTextSpanFromBounds ( position , position - indentPosition ) ,
567
+ newText : ""
568
+ } ) ;
582
569
}
583
570
}
584
571
}
0 commit comments