diff --git a/extensions/emmet/src/abbreviationActions.ts b/extensions/emmet/src/abbreviationActions.ts index 4ee8e221f99c1..f332aff2e000e 100644 --- a/extensions/emmet/src/abbreviationActions.ts +++ b/extensions/emmet/src/abbreviationActions.ts @@ -54,7 +54,11 @@ function doWrapping(individualLines: boolean, args: any) { return; } } - const syntax = 'html'; + args = args || {}; + if (!args['language']) { + args['language'] = editor.document.languageId; + } + const syntax = getSyntaxFromArgs(args) || 'html'; const rootNode = parseDocument(editor.document, false); let inPreview = false; diff --git a/extensions/emmet/src/test/wrapWithAbbreviation.test.ts b/extensions/emmet/src/test/wrapWithAbbreviation.test.ts index 9fc924508e244..d5a4a2bce3cd0 100644 --- a/extensions/emmet/src/test/wrapWithAbbreviation.test.ts +++ b/extensions/emmet/src/test/wrapWithAbbreviation.test.ts @@ -134,19 +134,7 @@ suite('Tests for Wrap with Abbreviations', () => { `; - - return withRandomFileEditor(contents, 'html', (editor, _) => { - editor.selections = [new Selection(2, 0, 2, 0)]; - const promise = wrapWithAbbreviation({ abbreviation: 'li.hello|c' }); - if (!promise) { - assert.equal(1, 2, 'Wrap returned undefined instead of promise.'); - return Promise.resolve(); - } - return promise.then(() => { - assert.equal(editor.document.getText(), expectedContents); - return Promise.resolve(); - }); - }); + return testWrapWithAbbreviation([new Selection(2, 0, 2, 0)], 'li.hello|c', expectedContents, contents); }); test('Wrap with abbreviation entire node when cursor is on opening tag', () => { @@ -162,19 +150,7 @@ suite('Tests for Wrap with Abbreviations', () => { `; - - return withRandomFileEditor(contents, 'html', (editor, _) => { - editor.selections = [new Selection(1, 1, 1, 1)]; - const promise = wrapWithAbbreviation({ abbreviation: 'div' }); - if (!promise) { - assert.equal(1, 2, 'Wrap returned undefined instead of promise.'); - return Promise.resolve(); - } - return promise.then(() => { - assert.equal(editor.document.getText(), expectedContents); - return Promise.resolve(); - }); - }); + return testWrapWithAbbreviation([new Selection(1, 1, 1, 1)], 'div', expectedContents, contents); }); test('Wrap with abbreviation entire node when cursor is on closing tag', () => { @@ -190,19 +166,7 @@ suite('Tests for Wrap with Abbreviations', () => { `; - - return withRandomFileEditor(contents, 'html', (editor, _) => { - editor.selections = [new Selection(3, 1, 3, 1)]; - const promise = wrapWithAbbreviation({ abbreviation: 'div' }); - if (!promise) { - assert.equal(1, 2, 'Wrap returned undefined instead of promise.'); - return Promise.resolve(); - } - return promise.then(() => { - assert.equal(editor.document.getText(), expectedContents); - return Promise.resolve(); - }); - }); + return testWrapWithAbbreviation([new Selection(3, 1, 3, 1)], 'div', expectedContents, contents); }); test('Wrap with multiline abbreviation doesnt add extra spaces', () => { @@ -215,19 +179,7 @@ suite('Tests for Wrap with Abbreviations', () => {
  • hello
  • `; - - return withRandomFileEditor(contents, 'html', (editor, _) => { - editor.selections = [new Selection(1, 2, 1, 2)]; - const promise = wrapWithAbbreviation({ abbreviation: 'ul>li>a' }); - if (!promise) { - assert.equal(1, 2, 'Wrap returned undefined instead of promise.'); - return Promise.resolve(); - } - return promise.then(() => { - assert.equal(editor.document.getText(), expectedContents); - return Promise.resolve(); - }); - }); + return testWrapWithAbbreviation([new Selection(1, 2, 1, 2)], 'ul>li>a', expectedContents, contents); }); test('Wrap individual lines with abbreviation', () => { @@ -245,18 +197,7 @@ suite('Tests for Wrap with Abbreviations', () => { `; - return withRandomFileEditor(contents, 'html', (editor, _) => { - editor.selections = [new Selection(2, 2, 3, 33)]; - const promise = wrapIndividualLinesWithAbbreviation({ abbreviation: 'ul>li.hello$*' }); - if (!promise) { - assert.equal(1, 2, 'Wrap Individual Lines with Abbreviation returned undefined.'); - return Promise.resolve(); - } - return promise.then(() => { - assert.equal(editor.document.getText(), wrapIndividualLinesExpected); - return Promise.resolve(); - }); - }); + return testWrapIndividualLinesWithAbbreviation([new Selection(2, 2, 3, 33)], 'ul>li.hello$*', wrapIndividualLinesExpected, contents); }); test('Wrap individual lines with abbreviation with extra space selected', () => { @@ -274,18 +215,7 @@ suite('Tests for Wrap with Abbreviations', () => { `; - return withRandomFileEditor(contents, 'html', (editor, _) => { - editor.selections = [new Selection(2, 1, 4, 0)]; - const promise = wrapIndividualLinesWithAbbreviation({ abbreviation: 'ul>li.hello$*' }); - if (!promise) { - assert.equal(1, 2, 'Wrap Individual Lines with Abbreviation returned undefined.'); - return Promise.resolve(); - } - return promise.then(() => { - assert.equal(editor.document.getText(), wrapIndividualLinesExpected); - return Promise.resolve(); - }); - }); + return testWrapIndividualLinesWithAbbreviation([new Selection(2, 1, 4, 0)], 'ul>li.hello$*', wrapIndividualLinesExpected, contents); }); test('Wrap individual lines with abbreviation with comment filter', () => { @@ -305,18 +235,7 @@ suite('Tests for Wrap with Abbreviations', () => { `; - return withRandomFileEditor(contents, 'html', (editor, _) => { - editor.selections = [new Selection(2, 2, 3, 33)]; - const promise = wrapIndividualLinesWithAbbreviation({ abbreviation: 'ul>li.hello*|c' }); - if (!promise) { - assert.equal(1, 2, 'Wrap Individual Lines with Abbreviation returned undefined.'); - return Promise.resolve(); - } - return promise.then(() => { - assert.equal(editor.document.getText(), wrapIndividualLinesExpected); - return Promise.resolve(); - }); - }); + return testWrapIndividualLinesWithAbbreviation([new Selection(2, 2, 3, 33)], 'ul>li.hello*|c', wrapIndividualLinesExpected, contents); }); test('Wrap individual lines with abbreviation and trim', () => { @@ -334,19 +253,7 @@ suite('Tests for Wrap with Abbreviations', () => { `; - return withRandomFileEditor(contents, 'html', (editor, _) => { - editor.selections = [new Selection(2, 3, 3, 16)]; - const promise = wrapIndividualLinesWithAbbreviation({ abbreviation: 'ul>li.hello$*|t' }); - if (!promise) { - assert.equal(1, 2, 'Wrap Individual Lines with Abbreviation returned undefined.'); - return Promise.resolve(); - } - - return promise.then(() => { - assert.equal(editor.document.getText(), wrapIndividualLinesExpected); - return Promise.resolve(); - }); - }); + return testWrapIndividualLinesWithAbbreviation([new Selection(2, 3, 3, 16)], 'ul>li.hello$*|t', wrapIndividualLinesExpected, contents); }); test('Wrap with abbreviation and format set to false', () => { @@ -384,11 +291,35 @@ suite('Tests for Wrap with Abbreviations', () => { return testWrapWithAbbreviation([new Selection(2, 4, 3, 9), new Selection(5, 4, 6, 9)], 'div', wrapMultiLineExpected, htmlContentsForWrapMultiLineTests); }); + + test('Wrap multiline with abbreviation uses className for jsx files', () => { + const wrapMultiLineJsxExpected = ` + +`; + + return testWrapWithAbbreviation([new Selection(2,2,3,33)], '.hello', wrapMultiLineJsxExpected, htmlContentsForWrapTests, 'jsx'); + }); + + test('Wrap individual line with abbreviation uses className for jsx files', () => { + const wrapIndividualLinesJsxExpected = ` + +`; + + return testWrapIndividualLinesWithAbbreviation([new Selection(2,2,3,33)], '.hello$*', wrapIndividualLinesJsxExpected, htmlContentsForWrapTests, 'jsx'); + }); }); -function testWrapWithAbbreviation(selections: Selection[], abbreviation: string, expectedContents: string, input: string = htmlContentsForWrapTests): Thenable { - return withRandomFileEditor(input, 'html', (editor, _) => { +function testWrapWithAbbreviation(selections: Selection[], abbreviation: string, expectedContents: string, input: string = htmlContentsForWrapTests, fileExtension: string = 'html'): Thenable { + return withRandomFileEditor(input, fileExtension, (editor, _) => { editor.selections = selections; const promise = wrapWithAbbreviation({ abbreviation }); if (!promise) { @@ -402,3 +333,19 @@ function testWrapWithAbbreviation(selections: Selection[], abbreviation: string, }); }); } + +function testWrapIndividualLinesWithAbbreviation(selections: Selection[], abbreviation: string, expectedContents: string, input: string = htmlContentsForWrapTests, fileExtension: string = 'html'): Thenable { + return withRandomFileEditor(input, fileExtension, (editor, _) => { + editor.selections = selections; + const promise = wrapIndividualLinesWithAbbreviation({ abbreviation }); + if (!promise) { + assert.equal(1, 2, 'Wrap individual lines with Abbreviation returned undefined.'); + return Promise.resolve(); + } + + return promise.then(() => { + assert.equal(editor.document.getText(), expectedContents); + return Promise.resolve(); + }); + }); +}