@@ -17,7 +17,7 @@ let markupSnippetKeysRegex: RegExp[];
17
17
const stylesheetCustomSnippetsKeyCache = new Map < string , string [ ] > ( ) ;
18
18
const htmlAbbreviationStartRegex = / ^ [ a - z , A - Z , ! , ( , [ , # , \. ] / ;
19
19
const htmlAbbreviationEndRegex = / [ a - z , A - Z , ! , ) , \] , # , \. , } , \d , * , $ ] $ / ;
20
- const cssAbbreviationRegex = / ^ [ a - z , A - Z , ! , @ , # ] / ;
20
+ const cssAbbreviationRegex = / ^ - ? [ a - z , A - Z , ! , @ , # ] / ;
21
21
const htmlAbbreviationRegex = / [ a - z , A - Z ] / ;
22
22
const emmetModes = [ 'html' , 'pug' , 'slim' , 'haml' , 'xml' , 'xsl' , 'jsx' , 'css' , 'scss' , 'sass' , 'less' , 'stylus' ] ;
23
23
const commonlyUsedTags = [ 'div' , 'span' , 'p' , 'b' , 'i' , 'body' , 'html' , 'ul' , 'ol' , 'li' , 'head' , 'section' , 'canvas' , 'dl' , 'dt' , 'dd' , 'em' , 'main' , 'figure' ,
@@ -91,7 +91,7 @@ export function doComplete(document: TextDocument, position: Position, syntax: s
91
91
// If abbreviation is valid, then expand it and ensure the expanded value is not noise
92
92
if ( isAbbreviationValid ( syntax , abbreviation ) ) {
93
93
try {
94
- expandedText = expand ( abbreviation , expandOptions ) ;
94
+ expandedText = expandAbbreviationHelper ( abbreviation , expandOptions ) ;
95
95
} catch ( e ) {
96
96
}
97
97
@@ -123,12 +123,13 @@ export function doComplete(document: TextDocument, position: Position, syntax: s
123
123
const stylesheetCustomSnippetsKeys = stylesheetCustomSnippetsKeyCache . has ( syntax ) ? stylesheetCustomSnippetsKeyCache . get ( syntax ) : stylesheetCustomSnippetsKeyCache . get ( 'css' ) ;
124
124
completionItems = makeSnippetSuggestion ( stylesheetCustomSnippetsKeys , currentWord , abbreviation , abbreviationRange , expandOptions , 'Emmet Custom Snippet' , false ) ;
125
125
126
- if ( ! completionItems . find ( x => x . textEdit . newText === expandedAbbr . textEdit . newText ) ) {
127
-
126
+ if ( ! completionItems . find ( x => x . textEdit . newText === expandedAbbr . textEdit . newText ) ) {
127
+
128
128
// Fix for https://github.com/Microsoft/vscode/issues/28933#issuecomment-309236902
129
129
// When user types in propertyname, emmet uses it to match with snippet names, resulting in width -> widows or font-family -> font: family
130
130
// Filter out those cases here.
131
- const abbrRegex = new RegExp ( '.*' + abbreviation . split ( '' ) . map ( x => x === '$' ? '\\$' : x ) . join ( '.*' ) + '.*' , 'i' ) ;
131
+ let abbreviationWithoutDashPrefix = abbreviation [ 0 ] == '-' ? abbreviation . slice ( 1 ) : abbreviation ;
132
+ const abbrRegex = new RegExp ( '.*' + abbreviationWithoutDashPrefix . split ( '' ) . map ( x => x === '$' ? '\\$' : x ) . join ( '.*' ) + '.*' , 'i' ) ;
132
133
if ( / \d / . test ( abbreviation ) || abbrRegex . test ( expandedAbbr . label ) ) {
133
134
completionItems . push ( expandedAbbr ) ;
134
135
}
@@ -220,8 +221,7 @@ function addFinalTabStop(text): string {
220
221
}
221
222
222
223
let maxTabStop = - 1 ;
223
- let maxTabStopStart = - 1 ;
224
- let maxTabStopEnd = - 1 ;
224
+ let maxTabStopRanges = [ ] ;
225
225
let foundLastStop = false ;
226
226
let replaceWithLastStop = false ;
227
227
let i = 0 ;
@@ -270,17 +270,22 @@ function addFinalTabStop(text): string {
270
270
// Decide to replace currentTabStop with ${0} only if its the max among all tabstops and is not a placeholder
271
271
if ( currentTabStop > maxTabStop ) {
272
272
maxTabStop = currentTabStop ;
273
- maxTabStopStart = foundPlaceholder ? - 1 : numberStart ;
274
- maxTabStopEnd = foundPlaceholder ? - 1 : numberEnd ;
273
+ maxTabStopRanges = [ { numberStart, numberEnd } ] ;
275
274
replaceWithLastStop = ! foundPlaceholder ;
275
+ } else if ( currentTabStop == maxTabStop ) {
276
+ maxTabStopRanges . push ( { numberStart, numberEnd} ) ;
276
277
}
277
278
}
278
279
} catch ( e ) {
279
280
280
281
}
281
282
282
283
if ( replaceWithLastStop && ! foundLastStop ) {
283
- text = text . substr ( 0 , maxTabStopStart ) + '0' + text . substr ( maxTabStopEnd ) ;
284
+ for ( let i = 0 ; i < maxTabStopRanges . length ; i ++ ) {
285
+ let rangeStart = maxTabStopRanges [ i ] . numberStart ;
286
+ let rangeEnd = maxTabStopRanges [ i ] . numberEnd ;
287
+ text = text . substr ( 0 , rangeStart ) + '0' + text . substr ( rangeEnd ) ;
288
+ }
284
289
}
285
290
286
291
return text ;
@@ -520,13 +525,28 @@ export function getExpandOptions(syntax: string, emmetConfig?: object, filter?:
520
525
} ;
521
526
}
522
527
528
+ function expandAbbreviationHelper ( abbreviation : string , options : any ) {
529
+ let expandedText ;
530
+ let prefixes = [ "-webkit-" , "-moz-" , "-ms-" , "-o-" ] ;
531
+ abbreviation = abbreviation || "" ;
532
+ if ( isStyleSheet ( options . syntax ) && abbreviation [ 0 ] == '-' ) {
533
+ let tmp = expand ( abbreviation . substr ( 1 ) , options ) ;
534
+ expandedText = tmp ;
535
+ for ( let index = 0 ; index < prefixes . length ; index ++ ) {
536
+ expandedText += "\n" + prefixes [ index ] + tmp ;
537
+ }
538
+ } else {
539
+ expandedText = expand ( abbreviation , options ) ;
540
+ }
541
+ return expandedText ;
542
+ }
523
543
/**
524
544
* Expands given abbreviation using given options
525
545
* @param abbreviation string
526
546
* @param options
527
547
*/
528
548
export function expandAbbreviation ( abbreviation : string , options : any ) {
529
- let expandedText = expand ( abbreviation , options ) ;
549
+ let expandedText = expandAbbreviationHelper ( abbreviation , options ) ;
530
550
return escapeNonTabStopDollar ( addFinalTabStop ( expandedText ) ) ;
531
551
}
532
552
0 commit comments