@@ -60,47 +60,6 @@ function getPrecedingValidLine(model: IVirtualModel, lineNumber: number, process
60
60
return - 1 ;
61
61
}
62
62
63
- /**
64
- * Get indentation for line from reference line
65
- */
66
- function getIndentationForLineFromReferenceLine (
67
- autoIndent : EditorAutoIndentStrategy ,
68
- model : IVirtualModel ,
69
- languageConfigurationService : ILanguageConfigurationService ,
70
- considerOnEnterRulesForInheritedIndentAfterBlankLine : boolean ,
71
- indentConverter : IIndentConverter | undefined ,
72
- referencePrevLineNum : number ,
73
- currentLineNumber : number
74
- ) : string {
75
- let indentation = strings . getLeadingWhitespace ( model . getLineContent ( referencePrevLineNum ) ) ;
76
- // Check for onEnter rules that should decrease the indent
77
- if ( indentConverter && considerOnEnterRulesForInheritedIndentAfterBlankLine ) {
78
- const richEditSupport = languageConfigurationService . getLanguageConfiguration ( model . tokenization . getLanguageId ( ) ) ;
79
- if ( richEditSupport ) {
80
- const previousLineText = referencePrevLineNum < 1 ? '' : model . getLineContent ( referencePrevLineNum - 1 ) ;
81
- let afterEnterText = "" ;
82
- try {
83
- afterEnterText = model . getLineContent ( currentLineNumber ) ;
84
- } catch ( e ) {
85
- // Probably after the end of file
86
- }
87
- const referencePrevLineNumContent = model . getLineContent ( referencePrevLineNum ) ;
88
- const enterResult = richEditSupport . onEnter ( autoIndent , previousLineText , referencePrevLineNumContent , afterEnterText ) ;
89
- if ( enterResult ) {
90
- if ( enterResult . indentAction === IndentAction . Outdent ) {
91
- indentation = indentConverter . unshiftIndent ( indentation ) ;
92
- } else if ( enterResult . indentAction === IndentAction . Indent ) {
93
- indentation = indentConverter . shiftIndent ( indentation ) ;
94
- } else if ( enterResult . removeText && indentation . length >= enterResult . removeText ) {
95
- indentation = indentation . substring ( 0 , indentation . length - enterResult . removeText - 1 ) ;
96
- }
97
- }
98
- }
99
- }
100
-
101
- return indentation ;
102
- }
103
-
104
63
/**
105
64
* Get inherited indentation from above lines.
106
65
* 1. Find the nearest preceding line which doesn't match unIndentedLinePattern.
@@ -115,12 +74,11 @@ function getIndentationForLineFromReferenceLine(
115
74
*/
116
75
export function getInheritIndentForLine (
117
76
autoIndent : EditorAutoIndentStrategy ,
118
- considerOnEnterRulesForInheritedIndentAfterBlankLine : boolean ,
77
+ useOnEnterRulesForInheritedIndent : boolean ,
119
78
model : IVirtualModel ,
120
79
lineNumber : number ,
121
80
honorIntentialIndent : boolean = true ,
122
- languageConfigurationService : ILanguageConfigurationService ,
123
- indentConverter : IIndentConverter | undefined
81
+ languageConfigurationService : ILanguageConfigurationService
124
82
) : { indentation : string ; action : IndentAction | null ; line ?: number } | null {
125
83
if ( autoIndent < EditorAutoIndentStrategy . Full ) {
126
84
return null ;
@@ -130,7 +88,7 @@ export function getInheritIndentForLine(
130
88
if ( ! indentRulesSupport ) {
131
89
return null ;
132
90
}
133
- const processedIndentRulesSupport = new ProcessedIndentRulesSupport ( model , indentRulesSupport , languageConfigurationService ) ;
91
+ const processedIndentRulesSupport = new ProcessedIndentRulesSupport ( model , autoIndent , useOnEnterRulesForInheritedIndent , indentRulesSupport , languageConfigurationService ) ;
134
92
135
93
if ( lineNumber <= 1 ) {
136
94
return {
@@ -192,7 +150,7 @@ export function getInheritIndentForLine(
192
150
193
151
const previousLine = precedingUnIgnoredLine - 1 ;
194
152
195
- const previousLineIndentMetadata = indentRulesSupport . getIndentMetadata ( model . getLineContent ( previousLine ) ) ;
153
+ const previousLineIndentMetadata = indentRulesSupport . getIndentMetadata ( autoIndent , useOnEnterRulesForInheritedIndent , model . getLineContent ( previousLine ) ) ;
196
154
if ( ! ( previousLineIndentMetadata & ( IndentConsts . INCREASE_MASK | IndentConsts . DECREASE_MASK ) ) &&
197
155
( previousLineIndentMetadata & IndentConsts . INDENT_NEXTLINE_MASK ) ) {
198
156
let stopLine = 0 ;
@@ -213,7 +171,7 @@ export function getInheritIndentForLine(
213
171
214
172
if ( honorIntentialIndent ) {
215
173
return {
216
- indentation : getIndentationForLineFromReferenceLine ( autoIndent , model , languageConfigurationService , considerOnEnterRulesForInheritedIndentAfterBlankLine , indentConverter , precedingUnIgnoredLine , lineNumber ) ,
174
+ indentation : strings . getLeadingWhitespace ( model . getLineContent ( precedingUnIgnoredLine ) ) ,
217
175
action : null ,
218
176
line : precedingUnIgnoredLine
219
177
} ;
@@ -261,7 +219,7 @@ export function getInheritIndentForLine(
261
219
262
220
export function getGoodIndentForLine (
263
221
autoIndent : EditorAutoIndentStrategy ,
264
- considerOnEnterRulesForInheritedIndentAfterBlankLine : boolean ,
222
+ useOnEnterRulesForInheritedIndent : boolean ,
265
223
virtualModel : IVirtualModel ,
266
224
languageId : string ,
267
225
lineNumber : number ,
@@ -282,8 +240,8 @@ export function getGoodIndentForLine(
282
240
return null ;
283
241
}
284
242
285
- const processedIndentRulesSupport = new ProcessedIndentRulesSupport ( virtualModel , indentRulesSupport , languageConfigurationService ) ;
286
- const indent = getInheritIndentForLine ( autoIndent , considerOnEnterRulesForInheritedIndentAfterBlankLine , virtualModel , lineNumber , undefined , languageConfigurationService , indentConverter ) ;
243
+ const processedIndentRulesSupport = new ProcessedIndentRulesSupport ( virtualModel , autoIndent , useOnEnterRulesForInheritedIndent , indentRulesSupport , languageConfigurationService ) ;
244
+ const indent = getInheritIndentForLine ( autoIndent , useOnEnterRulesForInheritedIndent , virtualModel , lineNumber , undefined , languageConfigurationService ) ;
287
245
288
246
if ( indent ) {
289
247
const inheritLine = indent . line ;
@@ -346,13 +304,13 @@ export function getGoodIndentForLine(
346
304
}
347
305
348
306
export function getIndentForEnter (
349
- autoIndent : EditorAutoIndentStrategy ,
350
- considerOnEnterRulesForInheritedIndentAfterBlankLine : boolean ,
307
+ cursorConfig : CursorConfiguration ,
351
308
model : ITextModel ,
352
309
range : Range ,
353
310
indentConverter : IIndentConverter ,
354
311
languageConfigurationService : ILanguageConfigurationService
355
312
) : { beforeEnter : string ; afterEnter : string } | null {
313
+ const autoIndent = cursorConfig . autoIndent ;
356
314
if ( autoIndent < EditorAutoIndentStrategy . Full ) {
357
315
return null ;
358
316
}
@@ -373,7 +331,7 @@ export function getIndentForEnter(
373
331
const languageIsDifferentFromLineStart = isLanguageDifferentFromLineStart ( model , range . getStartPosition ( ) ) ;
374
332
const currentLine = model . getLineContent ( range . startLineNumber ) ;
375
333
const currentLineIndent = strings . getLeadingWhitespace ( currentLine ) ;
376
- const afterEnterAction = getInheritIndentForLine ( autoIndent , considerOnEnterRulesForInheritedIndentAfterBlankLine , virtualModel , range . startLineNumber + 1 , undefined , languageConfigurationService , indentConverter ) ;
334
+ const afterEnterAction = getInheritIndentForLine ( cursorConfig . autoIndent , cursorConfig . useOnEnterRulesForInheritedIndent , virtualModel , range . startLineNumber + 1 , undefined , languageConfigurationService ) ;
377
335
if ( ! afterEnterAction ) {
378
336
const beforeEnter = languageIsDifferentFromLineStart ? currentLineIndent : beforeEnterIndent ;
379
337
return {
@@ -388,7 +346,7 @@ export function getIndentForEnter(
388
346
afterEnterIndent = indentConverter . shiftIndent ( afterEnterIndent ) ;
389
347
}
390
348
391
- if ( indentRulesSupport . shouldDecrease ( afterEnterProcessedTokens . getLineContent ( ) ) ) {
349
+ if ( indentRulesSupport . shouldDecrease ( cursorConfig . autoIndent , cursorConfig . useOnEnterRulesForInheritedIndent , afterEnterProcessedTokens . getLineContent ( ) ) ) {
392
350
afterEnterIndent = indentConverter . unshiftIndent ( afterEnterIndent ) ;
393
351
}
394
352
@@ -414,7 +372,6 @@ export function getIndentActionForType(
414
372
if ( autoIndent < EditorAutoIndentStrategy . Full ) {
415
373
return null ;
416
374
}
417
- const considerOnEnterRulesForInheritedIndentAfterBlankLine = cursorConfig . considerOnEnterRulesForInheritedIndentAfterBlankLine ;
418
375
const languageIsDifferentFromLineStart = isLanguageDifferentFromLineStart ( model , range . getStartPosition ( ) ) ;
419
376
if ( languageIsDifferentFromLineStart ) {
420
377
// this line has mixed languages and indentation rules will not work
@@ -436,10 +393,10 @@ export function getIndentActionForType(
436
393
437
394
// If previous content already matches decreaseIndentPattern, it means indentation of this line should already be adjusted
438
395
// Users might change the indentation by purpose and we should honor that instead of readjusting.
439
- if ( ! indentRulesSupport . shouldDecrease ( textAroundRange ) && indentRulesSupport . shouldDecrease ( textAroundRangeWithCharacter ) ) {
396
+ if ( ! indentRulesSupport . shouldDecrease ( cursorConfig . autoIndent , cursorConfig . useOnEnterRulesForInheritedIndent , textAroundRange ) && indentRulesSupport . shouldDecrease ( cursorConfig . autoIndent , cursorConfig . useOnEnterRulesForInheritedIndent , textAroundRangeWithCharacter ) ) {
440
397
// after typing `ch`, the content matches decreaseIndentPattern, we should adjust the indent to a good manner.
441
398
// 1. Get inherited indent action
442
- const r = getInheritIndentForLine ( autoIndent , considerOnEnterRulesForInheritedIndentAfterBlankLine , model , range . startLineNumber , false , languageConfigurationService , indentConverter ) ;
399
+ const r = getInheritIndentForLine ( cursorConfig . autoIndent , cursorConfig . useOnEnterRulesForInheritedIndent , model , range . startLineNumber , false , languageConfigurationService ) ;
443
400
if ( ! r ) {
444
401
return null ;
445
402
}
@@ -455,8 +412,8 @@ export function getIndentActionForType(
455
412
const previousLineNumber = range . startLineNumber - 1 ;
456
413
if ( previousLineNumber > 0 ) {
457
414
const previousLine = model . getLineContent ( previousLineNumber ) ;
458
- if ( indentRulesSupport . shouldIndentNextLine ( previousLine ) && indentRulesSupport . shouldIncrease ( textAroundRangeWithCharacter ) ) {
459
- const inheritedIndentationData = getInheritIndentForLine ( autoIndent , considerOnEnterRulesForInheritedIndentAfterBlankLine , model , range . startLineNumber , false , languageConfigurationService , undefined ) ;
415
+ if ( indentRulesSupport . shouldIndentNextLine ( cursorConfig . autoIndent , cursorConfig . useOnEnterRulesForInheritedIndent , previousLine ) && indentRulesSupport . shouldIncrease ( cursorConfig . autoIndent , cursorConfig . useOnEnterRulesForInheritedIndent , textAroundRangeWithCharacter ) ) {
416
+ const inheritedIndentationData = getInheritIndentForLine ( cursorConfig . autoIndent , cursorConfig . useOnEnterRulesForInheritedIndent , model , range . startLineNumber , false , languageConfigurationService ) ;
460
417
const inheritedIndentation = inheritedIndentationData ?. indentation ;
461
418
if ( inheritedIndentation !== undefined ) {
462
419
const currentLine = model . getLineContent ( range . startLineNumber ) ;
@@ -480,6 +437,8 @@ export function getIndentActionForType(
480
437
481
438
export function getIndentMetadata (
482
439
model : ITextModel ,
440
+ autoIndent : EditorAutoIndentStrategy ,
441
+ useOnEnterRulesForInheritedIndent : boolean ,
483
442
lineNumber : number ,
484
443
languageConfigurationService : ILanguageConfigurationService
485
444
) : number | null {
@@ -490,7 +449,7 @@ export function getIndentMetadata(
490
449
if ( lineNumber < 1 || lineNumber > model . getLineCount ( ) ) {
491
450
return null ;
492
451
}
493
- return indentRulesSupport . getIndentMetadata ( model . getLineContent ( lineNumber ) ) ;
452
+ return indentRulesSupport . getIndentMetadata ( autoIndent , useOnEnterRulesForInheritedIndent , model . getLineContent ( lineNumber ) ) ;
494
453
}
495
454
496
455
function createVirtualModelWithModifiedTokensAtLine ( model : ITextModel , modifiedLineNumber : number , modifiedTokens : IViewLineTokens ) : IVirtualModel {
0 commit comments