@@ -366,7 +366,7 @@ export class LanguageConfigurationRegistryImpl {
366
366
*
367
367
* This function only return the inherited indent based on above lines, it doesn't check whether current line should decrease or not.
368
368
*/
369
- public getInheritIndentForLine ( autoIndent : EditorAutoIndentStrategy , model : IVirtualModel , lineNumber : number , honorIntentialIndent : boolean = true ) : { indentation : string ; action : IndentAction | null ; line ?: number ; } | null {
369
+ public getInheritIndentForLine ( autoIndent : EditorAutoIndentStrategy , model : IVirtualModel , lineNumber : number , honorIntentialIndent : boolean = true , indentConverter : IIndentConverter | undefined = undefined ) : { indentation : string ; action : IndentAction | null ; line ?: number ; } | null {
370
370
if ( autoIndent < EditorAutoIndentStrategy . Full ) {
371
371
return null ;
372
372
}
@@ -442,8 +442,26 @@ export class LanguageConfigurationRegistryImpl {
442
442
}
443
443
444
444
if ( honorIntentialIndent ) {
445
+ let indentation = strings . getLeadingWhitespace ( model . getLineContent ( precedingUnIgnoredLine ) ) ;
446
+ // Check for onEnter rules that should decrease the indent
447
+ if ( indentConverter ) {
448
+ const richEditSupport = this . getLanguageConfiguration ( model . getLanguageId ( ) ) ;
449
+ if ( richEditSupport ) {
450
+ const previousLineText = precedingUnIgnoredLine < 1 ? '' : model . getLineContent ( precedingUnIgnoredLine - 1 ) ;
451
+ const afterEnterText = model . getLineContent ( lineNumber ) ;
452
+ const enterResult = richEditSupport . onEnter ( autoIndent , previousLineText , precedingUnIgnoredLineContent , afterEnterText ) ;
453
+ if ( enterResult ) {
454
+ if ( enterResult . indentAction === IndentAction . Outdent ) {
455
+ indentation = indentConverter . unshiftIndent ( indentation ) ;
456
+ } else if ( enterResult . removeText && indentation . length >= enterResult . removeText ) {
457
+ indentation = indentation . substring ( 0 , indentation . length - enterResult . removeText - 1 ) ;
458
+ }
459
+ }
460
+ }
461
+ }
462
+
445
463
return {
446
- indentation : strings . getLeadingWhitespace ( model . getLineContent ( precedingUnIgnoredLine ) ) ,
464
+ indentation : indentation ,
447
465
action : null ,
448
466
line : precedingUnIgnoredLine
449
467
} ;
@@ -505,7 +523,7 @@ export class LanguageConfigurationRegistryImpl {
505
523
return null ;
506
524
}
507
525
508
- const indent = this . getInheritIndentForLine ( autoIndent , virtualModel , lineNumber ) ;
526
+ const indent = this . getInheritIndentForLine ( autoIndent , virtualModel , lineNumber , true , indentConverter ) ;
509
527
const lineContent = virtualModel . getLineContent ( lineNumber ) ;
510
528
511
529
if ( indent ) {
@@ -613,7 +631,7 @@ export class LanguageConfigurationRegistryImpl {
613
631
} ;
614
632
615
633
const currentLineIndent = strings . getLeadingWhitespace ( lineTokens . getLineContent ( ) ) ;
616
- const afterEnterAction = this . getInheritIndentForLine ( autoIndent , virtualModel , range . startLineNumber + 1 ) ;
634
+ const afterEnterAction = this . getInheritIndentForLine ( autoIndent , virtualModel , range . startLineNumber + 1 , true , indentConverter ) ;
617
635
if ( ! afterEnterAction ) {
618
636
const beforeEnter = embeddedLanguage ? currentLineIndent : beforeEnterIndent ;
619
637
return {
0 commit comments