@@ -264,47 +264,47 @@ export async function wrapWithAbbreviation(args: any): Promise<boolean> {
264
264
}
265
265
266
266
export function expandEmmetAbbreviation ( args : any ) : Thenable < boolean | undefined > {
267
- if ( ! validate ( ) ) {
268
- return Promise . resolve ( undefined ) ;
267
+ if ( ! validate ( ) || ! vscode . window . activeTextEditor ) {
268
+ return fallbackTab ( ) ;
269
269
}
270
270
271
- const editor = vscode . window . activeTextEditor ! ;
272
-
273
- args = args || { } ;
274
- if ( ! args [ 'language' ] ) {
275
- args [ 'language' ] = editor . document . languageId ;
276
- } else {
277
- const excludedLanguages = vscode . workspace . getConfiguration ( 'emmet' ) [ 'excludeLanguages' ] ?? [ ] ;
278
- if ( excludedLanguages . includes ( args [ 'language' ] ) ) {
279
- return fallbackTab ( args [ 'language' ] ) ;
280
- }
281
- }
282
- const languageId : string = args [ 'language' ] ;
283
-
284
271
/**
285
272
* Short circuit the parsing. If previous character is space, do not expand.
286
273
*/
287
- if ( editor . selections . length === 1 && editor . selection . isEmpty
274
+ if ( vscode . window . activeTextEditor . selections . length === 1 &&
275
+ vscode . window . activeTextEditor . selection . isEmpty
288
276
) {
289
- const anchor = editor . selection . anchor ;
277
+ const anchor = vscode . window . activeTextEditor . selection . anchor ;
290
278
if ( anchor . character === 0 ) {
291
- return fallbackTab ( languageId ) ;
279
+ return fallbackTab ( ) ;
292
280
}
293
281
294
282
const prevPositionAnchor = anchor . translate ( 0 , - 1 ) ;
295
- const prevText = editor . document . getText ( new vscode . Range ( prevPositionAnchor , anchor ) ) ;
283
+ const prevText = vscode . window . activeTextEditor . document . getText ( new vscode . Range ( prevPositionAnchor , anchor ) ) ;
296
284
if ( prevText === ' ' || prevText === '\t' ) {
297
- return fallbackTab ( languageId ) ;
285
+ return fallbackTab ( ) ;
298
286
}
299
287
}
300
288
289
+ args = args || { } ;
290
+ if ( ! args [ 'language' ] ) {
291
+ args [ 'language' ] = vscode . window . activeTextEditor . document . languageId ;
292
+ } else {
293
+ const excludedLanguages = vscode . workspace . getConfiguration ( 'emmet' ) [ 'excludeLanguages' ] ? vscode . workspace . getConfiguration ( 'emmet' ) [ 'excludeLanguages' ] : [ ] ;
294
+ if ( excludedLanguages . indexOf ( vscode . window . activeTextEditor . document . languageId ) > - 1 ) {
295
+ return fallbackTab ( ) ;
296
+ }
297
+ }
301
298
const syntax = getSyntaxFromArgs ( args ) ;
302
299
if ( ! syntax ) {
303
- return fallbackTab ( languageId ) ;
300
+ return fallbackTab ( ) ;
304
301
}
302
+
303
+ const editor = vscode . window . activeTextEditor ;
304
+
305
305
// When tabbed on a non empty selection, do not treat it as an emmet abbreviation, and fallback to tab instead
306
- if ( vscode . workspace . getConfiguration ( 'emmet' , { languageId } ) [ 'triggerExpansionOnTab' ] === true && editor . selections . find ( x => ! x . isEmpty ) ) {
307
- return fallbackTab ( languageId ) ;
306
+ if ( vscode . workspace . getConfiguration ( 'emmet' ) [ 'triggerExpansionOnTab' ] === true && editor . selections . find ( x => ! x . isEmpty ) ) {
307
+ return fallbackTab ( ) ;
308
308
}
309
309
310
310
const abbreviationList : ExpandAbbreviationInput [ ] = [ ] ;
@@ -325,7 +325,7 @@ export function expandEmmetAbbreviation(args: any): Thenable<boolean | undefined
325
325
}
326
326
327
327
const currentLine = editor . document . lineAt ( position . line ) . text ;
328
- const textTillPosition = currentLine . substring ( 0 , position . character ) ;
328
+ const textTillPosition = currentLine . substr ( 0 , position . character ) ;
329
329
330
330
// Expand cases like <div to <div></div> explicitly
331
331
// else we will end up with <<div></div>
@@ -415,12 +415,12 @@ export function expandEmmetAbbreviation(args: any): Thenable<boolean | undefined
415
415
} ) ;
416
416
417
417
return expandAbbreviationInRange ( editor , abbreviationList , allAbbreviationsSame ) . then ( success => {
418
- return success ? Promise . resolve ( undefined ) : fallbackTab ( languageId ) ;
418
+ return success ? Promise . resolve ( undefined ) : fallbackTab ( ) ;
419
419
} ) ;
420
420
}
421
421
422
- function fallbackTab ( languageId : string ) : Thenable < boolean | undefined > {
423
- if ( vscode . workspace . getConfiguration ( 'emmet' , { languageId } ) [ 'triggerExpansionOnTab' ] === true ) {
422
+ function fallbackTab ( ) : Thenable < boolean | undefined > {
423
+ if ( vscode . workspace . getConfiguration ( 'emmet' ) [ 'triggerExpansionOnTab' ] === true ) {
424
424
return vscode . commands . executeCommand ( 'tab' ) ;
425
425
}
426
426
return Promise . resolve ( true ) ;
@@ -470,13 +470,13 @@ export function isValidLocationForEmmetAbbreviation(document: vscode.TextDocumen
470
470
&& propertyNode . separator
471
471
&& offset >= propertyNode . separatorToken . end
472
472
&& offset <= propertyNode . terminatorToken . start
473
- && ! abbreviation . includes ( ':' ) ) {
473
+ && abbreviation . indexOf ( ':' ) === - 1 ) {
474
474
return hexColorRegex . test ( abbreviation ) || abbreviation === '!' ;
475
475
}
476
476
if ( ! propertyNode . terminatorToken
477
477
&& propertyNode . separator
478
478
&& offset >= propertyNode . separatorToken . end
479
- && ! abbreviation . includes ( ':' ) ) {
479
+ && abbreviation . indexOf ( ':' ) === - 1 ) {
480
480
return hexColorRegex . test ( abbreviation ) || abbreviation === '!' ;
481
481
}
482
482
if ( hexColorRegex . test ( abbreviation ) || abbreviation === '!' ) {
@@ -529,7 +529,7 @@ export function isValidLocationForEmmetAbbreviation(document: vscode.TextDocumen
529
529
const typeAttribute = ( currentHtmlNode . attributes || [ ] ) . filter ( x => x . name . toString ( ) === 'type' ) [ 0 ] ;
530
530
const typeValue = typeAttribute ? typeAttribute . value . toString ( ) : '' ;
531
531
532
- if ( allowedMimeTypesInScriptTag . includes ( typeValue ) ) {
532
+ if ( allowedMimeTypesInScriptTag . indexOf ( typeValue ) > - 1 ) {
533
533
return true ;
534
534
}
535
535
0 commit comments