@@ -35,7 +35,8 @@ export class TypeOperations {
3535 tabSize : config . tabSize ,
3636 indentSize : config . indentSize ,
3737 insertSpaces : config . insertSpaces ,
38- useTabStops : config . useTabStops
38+ useTabStops : config . useTabStops ,
39+ autoIndent : config . autoIndent
3940 } ) ;
4041 }
4142 return commands ;
@@ -49,7 +50,8 @@ export class TypeOperations {
4950 tabSize : config . tabSize ,
5051 indentSize : config . indentSize ,
5152 insertSpaces : config . insertSpaces ,
52- useTabStops : config . useTabStops
53+ useTabStops : config . useTabStops ,
54+ autoIndent : config . autoIndent
5355 } ) ;
5456 }
5557 return commands ;
@@ -150,15 +152,15 @@ export class TypeOperations {
150152 let action : IndentAction | EnterAction | null = null ;
151153 let indentation : string = '' ;
152154
153- let expectedIndentAction = config . autoIndent ? LanguageConfigurationRegistry . getInheritIndentForLine ( model , lineNumber , false ) : null ;
155+ const expectedIndentAction = LanguageConfigurationRegistry . getInheritIndentForLine ( config . autoIndent , model , lineNumber , false ) ;
154156 if ( expectedIndentAction ) {
155157 action = expectedIndentAction . action ;
156158 indentation = expectedIndentAction . indentation ;
157159 } else if ( lineNumber > 1 ) {
158160 let lastLineNumber : number ;
159161 for ( lastLineNumber = lineNumber - 1 ; lastLineNumber >= 1 ; lastLineNumber -- ) {
160- let lineText = model . getLineContent ( lastLineNumber ) ;
161- let nonWhitespaceIdx = strings . lastNonWhitespaceIndex ( lineText ) ;
162+ const lineText = model . getLineContent ( lastLineNumber ) ;
163+ const nonWhitespaceIdx = strings . lastNonWhitespaceIndex ( lineText ) ;
162164 if ( nonWhitespaceIdx >= 0 ) {
163165 break ;
164166 }
@@ -169,8 +171,8 @@ export class TypeOperations {
169171 return null ;
170172 }
171173
172- let maxColumn = model . getLineMaxColumn ( lastLineNumber ) ;
173- let expectedEnterAction = LanguageConfigurationRegistry . getEnterAction ( model , new Range ( lastLineNumber , maxColumn , lastLineNumber , maxColumn ) ) ;
174+ const maxColumn = model . getLineMaxColumn ( lastLineNumber ) ;
175+ const expectedEnterAction = LanguageConfigurationRegistry . getEnterAction ( config . autoIndent , model , new Range ( lastLineNumber , maxColumn , lastLineNumber , maxColumn ) ) ;
174176 if ( expectedEnterAction ) {
175177 indentation = expectedEnterAction . indentation ;
176178 action = expectedEnterAction . enterAction ;
@@ -252,7 +254,8 @@ export class TypeOperations {
252254 tabSize : config . tabSize ,
253255 indentSize : config . indentSize ,
254256 insertSpaces : config . insertSpaces ,
255- useTabStops : config . useTabStops
257+ useTabStops : config . useTabStops ,
258+ autoIndent : config . autoIndent
256259 } ) ;
257260 }
258261 }
@@ -290,21 +293,19 @@ export class TypeOperations {
290293 }
291294
292295 private static _enter ( config : CursorConfiguration , model : ITextModel , keepPosition : boolean , range : Range ) : ICommand {
293- if ( config . autoIndent2 === EditorAutoIndentStrategy . None ) {
296+ if ( config . autoIndent === EditorAutoIndentStrategy . None ) {
294297 return TypeOperations . _typeCommand ( range , '\n' , keepPosition ) ;
295298 }
296- if ( ! model . isCheapToTokenize ( range . getStartPosition ( ) . lineNumber ) || config . autoIndent2 === EditorAutoIndentStrategy . Keep ) {
299+ if ( ! model . isCheapToTokenize ( range . getStartPosition ( ) . lineNumber ) || config . autoIndent === EditorAutoIndentStrategy . Keep ) {
297300 let lineText = model . getLineContent ( range . startLineNumber ) ;
298301 let indentation = strings . getLeadingWhitespace ( lineText ) . substring ( 0 , range . startColumn - 1 ) ;
299302 return TypeOperations . _typeCommand ( range , '\n' + config . normalizeIndentation ( indentation ) , keepPosition ) ;
300303 }
301304
302- const autoIndent = config . autoIndent2 ;
303-
304- let r = LanguageConfigurationRegistry . getEnterAction ( model , range ) ;
305+ const r = LanguageConfigurationRegistry . getEnterAction ( config . autoIndent , model , range ) ;
305306 if ( r ) {
306- let enterAction = r . enterAction ;
307- let indentation = r . indentation ;
307+ const enterAction = r . enterAction ;
308+ const indentation = r . indentation ;
308309
309310 if ( enterAction . indentAction === IndentAction . None ) {
310311 // Nothing special
@@ -316,83 +317,76 @@ export class TypeOperations {
316317
317318 } else if ( enterAction . indentAction === IndentAction . IndentOutdent ) {
318319 // Ultra special
319- let normalIndent = config . normalizeIndentation ( indentation ) ;
320- let increasedIndent = config . normalizeIndentation ( indentation + enterAction . appendText ) ;
320+ const normalIndent = config . normalizeIndentation ( indentation ) ;
321+ const increasedIndent = config . normalizeIndentation ( indentation + enterAction . appendText ) ;
321322
322- let typeText = '\n' + increasedIndent + '\n' + normalIndent ;
323+ const typeText = '\n' + increasedIndent + '\n' + normalIndent ;
323324
324325 if ( keepPosition ) {
325326 return new ReplaceCommandWithoutChangingPosition ( range , typeText , true ) ;
326327 } else {
327328 return new ReplaceCommandWithOffsetCursorState ( range , typeText , - 1 , increasedIndent . length - normalIndent . length , true ) ;
328329 }
329330 } else if ( enterAction . indentAction === IndentAction . Outdent ) {
330- let actualIndentation = TypeOperations . unshiftIndent ( config , indentation ) ;
331+ const actualIndentation = TypeOperations . unshiftIndent ( config , indentation ) ;
331332 return TypeOperations . _typeCommand ( range , '\n' + config . normalizeIndentation ( actualIndentation + enterAction . appendText ) , keepPosition ) ;
332333 }
333334 }
334335
335- // no enter rules applied, we should check indentation rules then.
336- if ( ! config . autoIndent ) {
337- // Nothing special
338- let lineText = model . getLineContent ( range . startLineNumber ) ;
339- let indentation = strings . getLeadingWhitespace ( lineText ) . substring ( 0 , range . startColumn - 1 ) ;
340- return TypeOperations . _typeCommand ( range , '\n' + config . normalizeIndentation ( indentation ) , keepPosition ) ;
341- }
342-
343- let ir = LanguageConfigurationRegistry . getIndentForEnter ( model , range , {
344- unshiftIndent : ( indent ) => {
345- return TypeOperations . unshiftIndent ( config , indent ) ;
346- } ,
347- shiftIndent : ( indent ) => {
348- return TypeOperations . shiftIndent ( config , indent ) ;
349- } ,
350- normalizeIndentation : ( indent ) => {
351- return config . normalizeIndentation ( indent ) ;
352- }
353- } , config . autoIndent ) ;
336+ const lineText = model . getLineContent ( range . startLineNumber ) ;
337+ const indentation = strings . getLeadingWhitespace ( lineText ) . substring ( 0 , range . startColumn - 1 ) ;
354338
355- let lineText = model . getLineContent ( range . startLineNumber ) ;
356- let indentation = strings . getLeadingWhitespace ( lineText ) . substring ( 0 , range . startColumn - 1 ) ;
339+ if ( config . autoIndent >= EditorAutoIndentStrategy . Full ) {
340+ const ir = LanguageConfigurationRegistry . getIndentForEnter ( config . autoIndent , model , range , {
341+ unshiftIndent : ( indent ) => {
342+ return TypeOperations . unshiftIndent ( config , indent ) ;
343+ } ,
344+ shiftIndent : ( indent ) => {
345+ return TypeOperations . shiftIndent ( config , indent ) ;
346+ } ,
347+ normalizeIndentation : ( indent ) => {
348+ return config . normalizeIndentation ( indent ) ;
349+ }
350+ } ) ;
357351
358- if ( ir ) {
359- let oldEndViewColumn = CursorColumns . visibleColumnFromColumn2 ( config , model , range . getEndPosition ( ) ) ;
360- let oldEndColumn = range . endColumn ;
352+ if ( ir ) {
353+ let oldEndViewColumn = CursorColumns . visibleColumnFromColumn2 ( config , model , range . getEndPosition ( ) ) ;
354+ const oldEndColumn = range . endColumn ;
361355
362- let beforeText = '\n' ;
363- if ( indentation !== config . normalizeIndentation ( ir . beforeEnter ) ) {
364- beforeText = config . normalizeIndentation ( ir . beforeEnter ) + lineText . substring ( indentation . length , range . startColumn - 1 ) + '\n' ;
365- range = new Range ( range . startLineNumber , 1 , range . endLineNumber , range . endColumn ) ;
366- }
356+ let beforeText = '\n' ;
357+ if ( indentation !== config . normalizeIndentation ( ir . beforeEnter ) ) {
358+ beforeText = config . normalizeIndentation ( ir . beforeEnter ) + lineText . substring ( indentation . length , range . startColumn - 1 ) + '\n' ;
359+ range = new Range ( range . startLineNumber , 1 , range . endLineNumber , range . endColumn ) ;
360+ }
367361
368- let newLineContent = model . getLineContent ( range . endLineNumber ) ;
369- let firstNonWhitespace = strings . firstNonWhitespaceIndex ( newLineContent ) ;
370- if ( firstNonWhitespace >= 0 ) {
371- range = range . setEndPosition ( range . endLineNumber , Math . max ( range . endColumn , firstNonWhitespace + 1 ) ) ;
372- } else {
373- range = range . setEndPosition ( range . endLineNumber , model . getLineMaxColumn ( range . endLineNumber ) ) ;
374- }
362+ const newLineContent = model . getLineContent ( range . endLineNumber ) ;
363+ const firstNonWhitespace = strings . firstNonWhitespaceIndex ( newLineContent ) ;
364+ if ( firstNonWhitespace >= 0 ) {
365+ range = range . setEndPosition ( range . endLineNumber , Math . max ( range . endColumn , firstNonWhitespace + 1 ) ) ;
366+ } else {
367+ range = range . setEndPosition ( range . endLineNumber , model . getLineMaxColumn ( range . endLineNumber ) ) ;
368+ }
375369
376- if ( keepPosition ) {
377- return new ReplaceCommandWithoutChangingPosition ( range , beforeText + config . normalizeIndentation ( ir . afterEnter ) , true ) ;
378- } else {
379- let offset = 0 ;
380- if ( oldEndColumn <= firstNonWhitespace + 1 ) {
381- if ( ! config . insertSpaces ) {
382- oldEndViewColumn = Math . ceil ( oldEndViewColumn / config . indentSize ) ;
370+ if ( keepPosition ) {
371+ return new ReplaceCommandWithoutChangingPosition ( range , beforeText + config . normalizeIndentation ( ir . afterEnter ) , true ) ;
372+ } else {
373+ let offset = 0 ;
374+ if ( oldEndColumn <= firstNonWhitespace + 1 ) {
375+ if ( ! config . insertSpaces ) {
376+ oldEndViewColumn = Math . ceil ( oldEndViewColumn / config . indentSize ) ;
377+ }
378+ offset = Math . min ( oldEndViewColumn + 1 - config . normalizeIndentation ( ir . afterEnter ) . length - 1 , 0 ) ;
383379 }
384- offset = Math . min ( oldEndViewColumn + 1 - config . normalizeIndentation ( ir . afterEnter ) . length - 1 , 0 ) ;
380+ return new ReplaceCommandWithOffsetCursorState ( range , beforeText + config . normalizeIndentation ( ir . afterEnter ) , 0 , offset , true ) ;
385381 }
386- return new ReplaceCommandWithOffsetCursorState ( range , beforeText + config . normalizeIndentation ( ir . afterEnter ) , 0 , offset , true ) ;
387382 }
388-
389- } else {
390- return TypeOperations . _typeCommand ( range , '\n' + config . normalizeIndentation ( indentation ) , keepPosition ) ;
391383 }
384+
385+ return TypeOperations . _typeCommand ( range , '\n' + config . normalizeIndentation ( indentation ) , keepPosition ) ;
392386 }
393387
394388 private static _isAutoIndentType ( config : CursorConfiguration , model : ITextModel , selections : Selection [ ] ) : boolean {
395- if ( ! config . autoIndent ) {
389+ if ( config . autoIndent < EditorAutoIndentStrategy . Full ) {
396390 return false ;
397391 }
398392
@@ -406,8 +400,8 @@ export class TypeOperations {
406400 }
407401
408402 private static _runAutoIndentType ( config : CursorConfiguration , model : ITextModel , range : Range , ch : string ) : ICommand | null {
409- let currentIndentation = LanguageConfigurationRegistry . getIndentationAtPosition ( model , range . startLineNumber , range . startColumn ) ;
410- let actualIndentation = LanguageConfigurationRegistry . getIndentActionForType ( model , range , ch , {
403+ const currentIndentation = LanguageConfigurationRegistry . getIndentationAtPosition ( model , range . startLineNumber , range . startColumn ) ;
404+ const actualIndentation = LanguageConfigurationRegistry . getIndentActionForType ( config . autoIndent , model , range , ch , {
411405 shiftIndent : ( indentation ) => {
412406 return TypeOperations . shiftIndent ( config , indentation ) ;
413407 } ,
@@ -421,7 +415,7 @@ export class TypeOperations {
421415 }
422416
423417 if ( actualIndentation !== config . normalizeIndentation ( currentIndentation ) ) {
424- let firstNonWhitespace = model . getLineFirstNonWhitespaceColumn ( range . startLineNumber ) ;
418+ const firstNonWhitespace = model . getLineFirstNonWhitespaceColumn ( range . startLineNumber ) ;
425419 if ( firstNonWhitespace === 0 ) {
426420 return TypeOperations . _typeCommand (
427421 new Range ( range . startLineNumber , 0 , range . endLineNumber , range . endColumn ) ,
0 commit comments