@@ -264,47 +264,47 @@ export async function wrapWithAbbreviation(args: any): Promise<boolean> {
264264}
265265
266266export function expandEmmetAbbreviation ( args : any ) : Thenable < boolean | undefined > {
267- if ( ! validate ( ) ) {
268- return Promise . resolve ( undefined ) ;
267+ if ( ! validate ( ) || ! vscode . window . activeTextEditor ) {
268+ return fallbackTab ( ) ;
269269 }
270270
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-
284271 /**
285272 * Short circuit the parsing. If previous character is space, do not expand.
286273 */
287- if ( editor . selections . length === 1 && editor . selection . isEmpty
274+ if ( vscode . window . activeTextEditor . selections . length === 1 &&
275+ vscode . window . activeTextEditor . selection . isEmpty
288276 ) {
289- const anchor = editor . selection . anchor ;
277+ const anchor = vscode . window . activeTextEditor . selection . anchor ;
290278 if ( anchor . character === 0 ) {
291- return fallbackTab ( languageId ) ;
279+ return fallbackTab ( ) ;
292280 }
293281
294282 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 ) ) ;
296284 if ( prevText === ' ' || prevText === '\t' ) {
297- return fallbackTab ( languageId ) ;
285+ return fallbackTab ( ) ;
298286 }
299287 }
300288
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+ }
301298 const syntax = getSyntaxFromArgs ( args ) ;
302299 if ( ! syntax ) {
303- return fallbackTab ( languageId ) ;
300+ return fallbackTab ( ) ;
304301 }
302+
303+ const editor = vscode . window . activeTextEditor ;
304+
305305 // 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 ( ) ;
308308 }
309309
310310 const abbreviationList : ExpandAbbreviationInput [ ] = [ ] ;
@@ -325,7 +325,7 @@ export function expandEmmetAbbreviation(args: any): Thenable<boolean | undefined
325325 }
326326
327327 const currentLine = editor . document . lineAt ( position . line ) . text ;
328- const textTillPosition = currentLine . substring ( 0 , position . character ) ;
328+ const textTillPosition = currentLine . substr ( 0 , position . character ) ;
329329
330330 // Expand cases like <div to <div></div> explicitly
331331 // else we will end up with <<div></div>
@@ -415,12 +415,12 @@ export function expandEmmetAbbreviation(args: any): Thenable<boolean | undefined
415415 } ) ;
416416
417417 return expandAbbreviationInRange ( editor , abbreviationList , allAbbreviationsSame ) . then ( success => {
418- return success ? Promise . resolve ( undefined ) : fallbackTab ( languageId ) ;
418+ return success ? Promise . resolve ( undefined ) : fallbackTab ( ) ;
419419 } ) ;
420420}
421421
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 ) {
424424 return vscode . commands . executeCommand ( 'tab' ) ;
425425 }
426426 return Promise . resolve ( true ) ;
@@ -470,13 +470,13 @@ export function isValidLocationForEmmetAbbreviation(document: vscode.TextDocumen
470470 && propertyNode . separator
471471 && offset >= propertyNode . separatorToken . end
472472 && offset <= propertyNode . terminatorToken . start
473- && ! abbreviation . includes ( ':' ) ) {
473+ && abbreviation . indexOf ( ':' ) === - 1 ) {
474474 return hexColorRegex . test ( abbreviation ) || abbreviation === '!' ;
475475 }
476476 if ( ! propertyNode . terminatorToken
477477 && propertyNode . separator
478478 && offset >= propertyNode . separatorToken . end
479- && ! abbreviation . includes ( ':' ) ) {
479+ && abbreviation . indexOf ( ':' ) === - 1 ) {
480480 return hexColorRegex . test ( abbreviation ) || abbreviation === '!' ;
481481 }
482482 if ( hexColorRegex . test ( abbreviation ) || abbreviation === '!' ) {
@@ -529,7 +529,7 @@ export function isValidLocationForEmmetAbbreviation(document: vscode.TextDocumen
529529 const typeAttribute = ( currentHtmlNode . attributes || [ ] ) . filter ( x => x . name . toString ( ) === 'type' ) [ 0 ] ;
530530 const typeValue = typeAttribute ? typeAttribute . value . toString ( ) : '' ;
531531
532- if ( allowedMimeTypesInScriptTag . includes ( typeValue ) ) {
532+ if ( allowedMimeTypesInScriptTag . indexOf ( typeValue ) > - 1 ) {
533533 return true ;
534534 }
535535
0 commit comments