diff --git a/extensions/emmet/package.json b/extensions/emmet/package.json index 05af52c0dc70f..ed9854f9eda6a 100644 --- a/extensions/emmet/package.json +++ b/extensions/emmet/package.json @@ -78,6 +78,11 @@ } }, "commands": [ + { + "command": "editor.emmet.action.wrapIndividualLinesWithAbbreviation", + "title": "%command.wrapIndividualLinesWithAbbreviation%", + "category": "Emmet" + }, { "command": "editor.emmet.action.wrapWithAbbreviation", "title": "%command.wrapWithAbbreviation%", diff --git a/extensions/emmet/package.nls.json b/extensions/emmet/package.nls.json index 8844b8fcd4d50..5a21d5bc4790e 100644 --- a/extensions/emmet/package.nls.json +++ b/extensions/emmet/package.nls.json @@ -1,5 +1,6 @@ { "command.wrapWithAbbreviation": "Wrap with Abbreviation", + "command.wrapIndividualLinesWithAbbreviation": "Wrap Individual Lines with Abbreviation", "command.removeTag": "Remove Tag", "command.updateTag": "Update Tag", "command.matchTag": "Go to Matching Pair", diff --git a/extensions/emmet/src/abbreviationActions.ts b/extensions/emmet/src/abbreviationActions.ts index 9dda545e0fa94..ecd5f2074adc5 100644 --- a/extensions/emmet/src/abbreviationActions.ts +++ b/extensions/emmet/src/abbreviationActions.ts @@ -12,7 +12,7 @@ interface ExpandAbbreviationInput { syntax: string; abbreviation: string; rangeToReplace: vscode.Range; - textToWrap?: string; + textToWrap?: string | string[]; filters?: string[]; } @@ -48,6 +48,36 @@ export function wrapWithAbbreviation(args) { }); } +export function wrapIndividualLinesWithAbbreviation(args) { + if (!validate(false)) { + return; + } + + const editor = vscode.window.activeTextEditor; + if (editor.selection.isEmpty) { + vscode.window.showInformationMessage('Select more than 1 line and try again.'); + return; + } + + const abbreviationPromise = (args && args['abbreviation']) ? Promise.resolve(args['abbreviation']) : vscode.window.showInputBox({ prompt: 'Enter Abbreviation' }); + const syntax = getSyntaxFromArgs({ language: editor.document.languageId }) || 'html'; + const lines = editor.document.getText(editor.selection).split('\n').map(x => x.trim()); + + return abbreviationPromise.then(abbreviation => { + if (!abbreviation || !abbreviation.trim() || !isAbbreviationValid(syntax, abbreviation)) { return; } + + let input: ExpandAbbreviationInput = { + syntax, + abbreviation, + rangeToReplace: editor.selection, + textToWrap: lines + }; + + return expandAbbreviationInRange(editor, [input], true); + }); + +} + export function expandEmmetAbbreviation(args) { const syntax = getSyntaxFromArgs(args); if (!syntax || !validate()) { diff --git a/extensions/emmet/src/extension.ts b/extensions/emmet/src/extension.ts index d6c1c6ea51e88..a74279554cca8 100644 --- a/extensions/emmet/src/extension.ts +++ b/extensions/emmet/src/extension.ts @@ -5,7 +5,7 @@ import * as vscode from 'vscode'; import { DefaultCompletionItemProvider } from './defaultCompletionProvider'; -import { expandEmmetAbbreviation, wrapWithAbbreviation } from './abbreviationActions'; +import { expandEmmetAbbreviation, wrapWithAbbreviation, wrapIndividualLinesWithAbbreviation } from './abbreviationActions'; import { removeTag } from './removeTag'; import { updateTag } from './updateTag'; import { matchTag } from './matchTag'; @@ -31,6 +31,10 @@ export function activate(context: vscode.ExtensionContext) { wrapWithAbbreviation(args); })); + context.subscriptions.push(vscode.commands.registerCommand('editor.emmet.action.wrapIndividualLinesWithAbbreviation', (args) => { + wrapIndividualLinesWithAbbreviation(args); + })); + context.subscriptions.push(vscode.commands.registerCommand('emmet.expandAbbreviation', (args) => { expandEmmetAbbreviation(args); }));