@@ -12,7 +12,7 @@ import { Range } from 'vs/editor/common/core/range';
1212import { ITextModel } from 'vs/editor/common/model' ;
1313import { DEFAULT_WORD_REGEXP , ensureValidWordDefinition } from 'vs/editor/common/model/wordHelper' ;
1414import { LanguageId , LanguageIdentifier } from 'vs/editor/common/modes' ;
15- import { EnterAction , FoldingRules , IAutoClosingPair , IndentAction , IndentationRule , LanguageConfiguration , StandardAutoClosingPairConditional } from 'vs/editor/common/modes/languageConfiguration' ;
15+ import { EnterAction , FoldingRules , IAutoClosingPair , IndentAction , IndentationRule , LanguageConfiguration , StandardAutoClosingPairConditional , CompleteEnterAction } from 'vs/editor/common/modes/languageConfiguration' ;
1616import { createScopedLineTokens , ScopedLineTokens } from 'vs/editor/common/modes/supports' ;
1717import { CharacterPairSupport } from 'vs/editor/common/modes/supports/characterPair' ;
1818import { BracketElectricCharacterSupport , IElectricAction } from 'vs/editor/common/modes/supports/electricCharacter' ;
@@ -697,12 +697,7 @@ export class LanguageConfigurationRegistryImpl {
697697 return value . onEnter || null ;
698698 }
699699
700- public getRawEnterActionAtPosition ( autoIndent : EditorAutoIndentStrategy , model : ITextModel , lineNumber : number , column : number ) : EnterAction | null {
701- const r = this . getEnterAction ( autoIndent , model , new Range ( lineNumber , column , lineNumber , column ) ) ;
702- return r ? r . enterAction : null ;
703- }
704-
705- public getEnterAction ( autoIndent : EditorAutoIndentStrategy , model : ITextModel , range : Range ) : { enterAction : EnterAction ; indentation : string ; } | null {
700+ public getEnterAction ( autoIndent : EditorAutoIndentStrategy , model : ITextModel , range : Range ) : CompleteEnterAction | null {
706701 const scopedLineTokens = this . getScopedLineTokens ( model , range . startLineNumber , range . startColumn ) ;
707702 const onEnterSupport = this . _getOnEnterSupport ( scopedLineTokens . languageId ) ;
708703 if ( ! onEnterSupport ) {
@@ -740,28 +735,34 @@ export class LanguageConfigurationRegistryImpl {
740735
741736 if ( ! enterResult ) {
742737 return null ;
743- } else {
744- // Here we add `\t` to appendText first because enterAction is leveraging appendText and removeText to change indentation.
745- if ( ! enterResult . appendText ) {
746- if (
747- ( enterResult . indentAction === IndentAction . Indent ) ||
748- ( enterResult . indentAction === IndentAction . IndentOutdent )
749- ) {
750- enterResult . appendText = '\t' ;
751- } else {
752- enterResult . appendText = '' ;
753- }
738+ }
739+
740+ const indentAction = enterResult . indentAction ;
741+ let appendText = enterResult . appendText ;
742+ const removeText = enterResult . removeText || 0 ;
743+
744+ // Here we add `\t` to appendText first because enterAction is leveraging appendText and removeText to change indentation.
745+ if ( ! appendText ) {
746+ if (
747+ ( indentAction === IndentAction . Indent ) ||
748+ ( indentAction === IndentAction . IndentOutdent )
749+ ) {
750+ appendText = '\t' ;
751+ } else {
752+ appendText = '' ;
754753 }
755754 }
756755
757756 let indentation = this . getIndentationAtPosition ( model , range . startLineNumber , range . startColumn ) ;
758- if ( enterResult . removeText ) {
759- indentation = indentation . substring ( 0 , indentation . length - enterResult . removeText ) ;
757+ if ( removeText ) {
758+ indentation = indentation . substring ( 0 , indentation . length - removeText ) ;
760759 }
761760
762761 return {
763- enterAction : enterResult ,
764- indentation : indentation ,
762+ indentAction : indentAction ,
763+ appendText : appendText ,
764+ removeText : removeText ,
765+ indentation : indentation
765766 } ;
766767 }
767768
0 commit comments