@@ -185,17 +185,35 @@ function expandAbbreviationInRange(editor: vscode.TextEditor, expandAbbrList: Ex
185185 * If there is textToWrap, then given preceedingWhiteSpace is applied
186186 */
187187function expandAbbr ( input : ExpandAbbreviationInput , preceedingWhiteSpace : string , newLine : string ) : string {
188-
188+ // Expand the abbreviation
189189 let expandedText = expand ( input . abbreviation , getExpandOptions ( input . syntax , input . textToWrap ) ) ;
190190 if ( ! expandedText ) {
191191 return ;
192192 }
193193
194+ // If no text to wrap, then return the expanded text
194195 if ( ! input . textToWrap ) {
195196 return expandedText ;
196197 }
197198
198- return expandedText . split ( newLine ) . map ( line => preceedingWhiteSpace + line ) . join ( newLine ) ;
199+ // There was text to wrap, and the final expanded text is multi line
200+ // So add the preceedingWhiteSpace to each line
201+ if ( expandedText . indexOf ( '\n' ) > - 1 ) {
202+ return expandedText . split ( newLine ) . map ( line => preceedingWhiteSpace + line ) . join ( newLine ) ;
203+ }
204+
205+ // There was text to wrap and the final expanded text is single line
206+ // This can happen when the abbreviation was for an inline element
207+ // Remove the preceeding newLine + tab and the ending newLine, that was added to textToWrap
208+ // And re-expand the abbreviation
209+ let regex = newLine === '\n' ? / ^ \n \t ( .* ) \n $ / : / ^ \r \n \t ( .* ) \r \n $ / ;
210+ let matches = input . textToWrap . match ( regex ) ;
211+ if ( matches ) {
212+ input . textToWrap = matches [ 1 ] ;
213+ return expandAbbr ( input , preceedingWhiteSpace , newLine ) ;
214+ }
215+
216+ return preceedingWhiteSpace + expandedText ;
199217}
200218
201219function getSyntaxFromArgs ( args : any ) : string {
0 commit comments