@@ -286,6 +286,12 @@ export class TypeOperations {
286286 }
287287
288288 private static _enter ( config : CursorConfiguration , model : ITokenizedModel , keepPosition : boolean , range : Range ) : ICommand {
289+ if ( model . getFirstInvalidLineNumber ( ) < range . getStartPosition ( ) . lineNumber ) {
290+ let lineText = model . getLineContent ( range . startLineNumber ) ;
291+ let indentation = strings . getLeadingWhitespace ( lineText ) . substring ( 0 , range . startColumn - 1 ) ;
292+ return TypeOperations . _typeCommand ( range , '\n' + config . normalizeIndentation ( indentation ) , keepPosition ) ;
293+ }
294+
289295 let r = LanguageConfigurationRegistry . getEnterAction ( model , range ) ;
290296 if ( r ) {
291297 let enterAction = r . enterAction ;
@@ -369,6 +375,21 @@ export class TypeOperations {
369375 }
370376 }
371377
378+ private static _isAutoIndentType ( config : CursorConfiguration , model : ITokenizedModel , selections : Selection [ ] ) : boolean {
379+ if ( ! config . autoIndent ) {
380+ return false ;
381+ }
382+
383+ let firstInvalidLineNumber = model . getFirstInvalidLineNumber ( ) ;
384+ for ( let i = 0 , len = selections . length ; i < len ; i ++ ) {
385+ if ( firstInvalidLineNumber < selections [ i ] . getEndPosition ( ) . lineNumber ) {
386+ return false ;
387+ }
388+ }
389+
390+ return true ;
391+ }
392+
372393 private static _runAutoIndentType ( config : CursorConfiguration , model : ITokenizedModel , range : Range , ch : string ) : ICommand {
373394 let currentIndentation = LanguageConfigurationRegistry . getIndentationAtPosition ( model , range . startLineNumber , range . startColumn ) ;
374395 let actualIndentation = LanguageConfigurationRegistry . getIndentActionForType ( model , range , ch , {
@@ -585,12 +606,20 @@ export class TypeOperations {
585606 } ) ;
586607 }
587608
588- private static _typeInterceptorElectricChar ( config : CursorConfiguration , model : ITokenizedModel , selections : Selection , ch : string ) : EditOperationResult {
589- if ( ! config . electricChars . hasOwnProperty ( ch ) || ! selections . isEmpty ( ) ) {
609+ private static _isTypeInterceptorElectricChar ( config : CursorConfiguration , model : ITokenizedModel , selections : Selection [ ] ) {
610+ let firstInvalidLineNumber = model . getFirstInvalidLineNumber ( ) ;
611+ if ( selections . length === 1 && firstInvalidLineNumber >= selections [ 0 ] . getEndPosition ( ) . lineNumber ) {
612+ return true ;
613+ }
614+ return false ;
615+ }
616+
617+ private static _typeInterceptorElectricChar ( config : CursorConfiguration , model : ITokenizedModel , selection : Selection , ch : string ) : EditOperationResult {
618+ if ( ! config . electricChars . hasOwnProperty ( ch ) || ! selection . isEmpty ( ) ) {
590619 return null ;
591620 }
592621
593- let position = selections . getPosition ( ) ;
622+ let position = selection . getPosition ( ) ;
594623 model . forceTokenization ( position . lineNumber ) ;
595624 let lineTokens = model . getLineTokens ( position . lineNumber ) ;
596625
@@ -606,7 +635,7 @@ export class TypeOperations {
606635 }
607636
608637 if ( electricAction . appendText ) {
609- const command = new ReplaceCommandWithOffsetCursorState ( selections , ch + electricAction . appendText , 0 , - electricAction . appendText . length ) ;
638+ const command = new ReplaceCommandWithOffsetCursorState ( selection , ch + electricAction . appendText , 0 , - electricAction . appendText . length ) ;
610639 return new EditOperationResult ( [ command ] , {
611640 shouldPushStackElementBefore : false ,
612641 shouldPushStackElementAfter : true
@@ -661,7 +690,7 @@ export class TypeOperations {
661690 } ) ;
662691 }
663692
664- if ( config . autoIndent ) {
693+ if ( this . _isAutoIndentType ( config , model , selections ) ) {
665694 let indentCommand = this . _runAutoIndentType ( config , model , selections [ 0 ] , ch ) ;
666695 if ( indentCommand ) {
667696 return new EditOperationResult ( [ indentCommand ] , {
@@ -685,7 +714,7 @@ export class TypeOperations {
685714
686715 // Electric characters make sense only when dealing with a single cursor,
687716 // as multiple cursors typing brackets for example would interfer with bracket matching
688- if ( selections . length === 1 ) {
717+ if ( this . _isTypeInterceptorElectricChar ( config , model , selections ) ) {
689718 const r = this . _typeInterceptorElectricChar ( config , model , selections [ 0 ] , ch ) ;
690719 if ( r ) {
691720 return r ;
0 commit comments