@@ -75,7 +75,8 @@ export function getInheritIndentForLine(
75
75
model : IVirtualModel ,
76
76
lineNumber : number ,
77
77
honorIntentialIndent : boolean = true ,
78
- languageConfigurationService : ILanguageConfigurationService
78
+ languageConfigurationService : ILanguageConfigurationService ,
79
+ indentConverter : IIndentConverter | undefined = undefined
79
80
) : { indentation : string ; action : IndentAction | null ; line ?: number } | null {
80
81
if ( autoIndent < EditorAutoIndentStrategy . Full ) {
81
82
return null ;
@@ -152,8 +153,26 @@ export function getInheritIndentForLine(
152
153
}
153
154
154
155
if ( honorIntentialIndent ) {
156
+ let indentation = strings . getLeadingWhitespace ( model . getLineContent ( precedingUnIgnoredLine ) ) ;
157
+ // Check for onEnter rules that should decrease the indent
158
+ if ( indentConverter ) {
159
+ const richEditSupport = languageConfigurationService . getLanguageConfiguration ( model . tokenization . getLanguageId ( ) ) ;
160
+ if ( richEditSupport ) {
161
+ const previousLineText = precedingUnIgnoredLine < 1 ? '' : model . getLineContent ( precedingUnIgnoredLine - 1 ) ;
162
+ const afterEnterText = model . getLineContent ( lineNumber ) ;
163
+ const enterResult = richEditSupport . onEnter ( autoIndent , previousLineText , precedingUnIgnoredLineContent , afterEnterText ) ;
164
+ if ( enterResult ) {
165
+ if ( enterResult . indentAction === IndentAction . Outdent ) {
166
+ indentation = indentConverter . unshiftIndent ( indentation ) ;
167
+ } else if ( enterResult . removeText && indentation . length >= enterResult . removeText ) {
168
+ indentation = indentation . substring ( 0 , indentation . length - enterResult . removeText - 1 ) ;
169
+ }
170
+ }
171
+ }
172
+ }
173
+
155
174
return {
156
- indentation : strings . getLeadingWhitespace ( model . getLineContent ( precedingUnIgnoredLine ) ) ,
175
+ indentation : indentation ,
157
176
action : null ,
158
177
line : precedingUnIgnoredLine
159
178
} ;
@@ -222,7 +241,7 @@ export function getGoodIndentForLine(
222
241
return null ;
223
242
}
224
243
225
- const indent = getInheritIndentForLine ( autoIndent , virtualModel , lineNumber , undefined , languageConfigurationService ) ;
244
+ const indent = getInheritIndentForLine ( autoIndent , virtualModel , lineNumber , undefined , languageConfigurationService , indentConverter ) ;
226
245
const lineContent = virtualModel . getLineContent ( lineNumber ) ;
227
246
228
247
if ( indent ) {
@@ -338,7 +357,7 @@ export function getIndentForEnter(
338
357
} ;
339
358
340
359
const currentLineIndent = strings . getLeadingWhitespace ( lineTokens . getLineContent ( ) ) ;
341
- const afterEnterAction = getInheritIndentForLine ( autoIndent , virtualModel , range . startLineNumber + 1 , undefined , languageConfigurationService ) ;
360
+ const afterEnterAction = getInheritIndentForLine ( autoIndent , virtualModel , range . startLineNumber + 1 , undefined , languageConfigurationService , indentConverter ) ;
342
361
if ( ! afterEnterAction ) {
343
362
const beforeEnter = embeddedLanguage ? currentLineIndent : beforeEnterIndent ;
344
363
return {
@@ -407,7 +426,7 @@ export function getIndentActionForType(
407
426
if ( ! indentRulesSupport . shouldDecrease ( beforeTypeText + afterTypeText ) && indentRulesSupport . shouldDecrease ( beforeTypeText + ch + afterTypeText ) ) {
408
427
// after typing `ch`, the content matches decreaseIndentPattern, we should adjust the indent to a good manner.
409
428
// 1. Get inherited indent action
410
- const r = getInheritIndentForLine ( autoIndent , model , range . startLineNumber , false , languageConfigurationService ) ;
429
+ const r = getInheritIndentForLine ( autoIndent , model , range . startLineNumber , false , languageConfigurationService , indentConverter ) ;
411
430
if ( ! r ) {
412
431
return null ;
413
432
}
0 commit comments