@@ -15,10 +15,12 @@ import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageCo
1515export class BlockCommentCommand implements ICommand {
1616
1717 private readonly _selection : Selection ;
18+ private readonly _insertSpace : boolean ;
1819 private _usedEndToken : string | null ;
1920
20- constructor ( selection : Selection ) {
21+ constructor ( selection : Selection , insertSpace : boolean ) {
2122 this . _selection = selection ;
23+ this . _insertSpace = insertSpace ;
2224 this . _usedEndToken = null ;
2325 }
2426
@@ -53,7 +55,7 @@ export class BlockCommentCommand implements ICommand {
5355 return true ;
5456 }
5557
56- private _createOperationsForBlockComment ( selection : Range , startToken : string , endToken : string , model : ITextModel , builder : IEditOperationBuilder ) : void {
58+ private _createOperationsForBlockComment ( selection : Range , startToken : string , endToken : string , insertSpace : boolean , model : ITextModel , builder : IEditOperationBuilder ) : void {
5759 const startLineNumber = selection . startLineNumber ;
5860 const startColumn = selection . startColumn ;
5961 const endLineNumber = selection . endLineNumber ;
@@ -91,25 +93,21 @@ export class BlockCommentCommand implements ICommand {
9193
9294 if ( startTokenIndex !== - 1 && endTokenIndex !== - 1 ) {
9395 // Consider spaces as part of the comment tokens
94- if ( startTokenIndex + startToken . length < startLineText . length ) {
95- if ( startLineText . charCodeAt ( startTokenIndex + startToken . length ) === CharCode . Space ) {
96- // Pretend the start token contains a trailing space
97- startToken = startToken + ' ' ;
98- }
96+ if ( insertSpace && startTokenIndex + startToken . length < startLineText . length && startLineText . charCodeAt ( startTokenIndex + startToken . length ) === CharCode . Space ) {
97+ // Pretend the start token contains a trailing space
98+ startToken = startToken + ' ' ;
9999 }
100100
101- if ( endTokenIndex > 0 ) {
102- if ( endLineText . charCodeAt ( endTokenIndex - 1 ) === CharCode . Space ) {
103- // Pretend the end token contains a leading space
104- endToken = ' ' + endToken ;
105- endTokenIndex -= 1 ;
106- }
101+ if ( insertSpace && endTokenIndex > 0 && endLineText . charCodeAt ( endTokenIndex - 1 ) === CharCode . Space ) {
102+ // Pretend the end token contains a leading space
103+ endToken = ' ' + endToken ;
104+ endTokenIndex -= 1 ;
107105 }
108106 ops = BlockCommentCommand . _createRemoveBlockCommentOperations (
109107 new Range ( startLineNumber , startTokenIndex + startToken . length + 1 , endLineNumber , endTokenIndex + 1 ) , startToken , endToken
110108 ) ;
111109 } else {
112- ops = BlockCommentCommand . _createAddBlockCommentOperations ( selection , startToken , endToken ) ;
110+ ops = BlockCommentCommand . _createAddBlockCommentOperations ( selection , startToken , endToken , this . _insertSpace ) ;
113111 this . _usedEndToken = ops . length === 1 ? endToken : null ;
114112 }
115113
@@ -144,15 +142,15 @@ export class BlockCommentCommand implements ICommand {
144142 return res ;
145143 }
146144
147- public static _createAddBlockCommentOperations ( r : Range , startToken : string , endToken : string ) : IIdentifiedSingleEditOperation [ ] {
145+ public static _createAddBlockCommentOperations ( r : Range , startToken : string , endToken : string , insertSpace : boolean ) : IIdentifiedSingleEditOperation [ ] {
148146 let res : IIdentifiedSingleEditOperation [ ] = [ ] ;
149147
150148 if ( ! Range . isEmpty ( r ) ) {
151149 // Insert block comment start
152- res . push ( EditOperation . insert ( new Position ( r . startLineNumber , r . startColumn ) , startToken + ' ' ) ) ;
150+ res . push ( EditOperation . insert ( new Position ( r . startLineNumber , r . startColumn ) , startToken + ( insertSpace ? ' ' : '' ) ) ) ;
153151
154152 // Insert block comment end
155- res . push ( EditOperation . insert ( new Position ( r . endLineNumber , r . endColumn ) , ' ' + endToken ) ) ;
153+ res . push ( EditOperation . insert ( new Position ( r . endLineNumber , r . endColumn ) , ( insertSpace ? ' ' : '' ) + endToken ) ) ;
156154 } else {
157155 // Insert both continuously
158156 res . push ( EditOperation . replace ( new Range (
@@ -176,7 +174,7 @@ export class BlockCommentCommand implements ICommand {
176174 return ;
177175 }
178176
179- this . _createOperationsForBlockComment ( this . _selection , config . blockCommentStartToken , config . blockCommentEndToken , model , builder ) ;
177+ this . _createOperationsForBlockComment ( this . _selection , config . blockCommentStartToken , config . blockCommentEndToken , this . _insertSpace , model , builder ) ;
180178 }
181179
182180 public computeCursorState ( model : ITextModel , helper : ICursorStateComputerData ) : Selection {
0 commit comments